I have the "mysite/poll" app from the Django tutorial running locally and am trying to deploy to GAE. I have defined DJANGO_SETTINGS_MODULE in the wsgi.py and admin.py as
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
This is the traceback on deployment:
Traceback (most recent call last):
File "/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 196, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 255, in _LoadHandler
handler = __import__(path[0])
File "/base/data/home/apps/s~ceemee11111/1.365096182895980177/admin.py", line 1, in <module>
from django.contrib import admin
File "/python27_runtime/python27_lib/versions/third_party/django-1.4/django/contrib/admin/__init__.py", line 3, in <module>
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
File "/python27_runtime/python27_lib/versions/third_party/django-1.4/django/contrib/admin/helpers.py", line 2, in <module>
from django.contrib.admin.util import (flatten_fieldsets, lookup_field,
File "/python27_runtime/python27_lib/versions/third_party/django- 1.4/django/contrib/admin/util.py", line 1, in <module>
from django.db import models
File "/python27_runtime/python27_lib/versions/third_party/django-1.4/django/db/__init__.py", line 11, in <module>
if DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/python27_runtime/python27_lib/versions/third_party/django-1.4/django/utils/functional.py", line 184, in inner
self._setup()
File "/python27_runtime/python27_lib/versions/third_party/django-1.4/django/conf/__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
why is the DJANGO_SETTINGS_MODULE still undefined
Thanks
Dan
https://developers.google.com/appengine/docs/python/tools/libraries27#django
You can also try add
env_variables:
DJANGO_SETTINGS_MODULE: 'myapp.settings'
in app.yaml
Try this instead:
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
Related
The project worked fine on windows pycharm.
Now i am putting it on ubuntu14.04 and apache2.
When i run python manage.py runserver 8000
Traceback (most recent call last): File "manage.py", line 14, in <module>
execute_from_command_line(sys.argv) File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute() File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/core/management/__init__.py", line 195, in fetch_command
klass = load_command_class(app_name, subcommand) File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/core/management/__init__.py", line 39, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name)) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name) File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/core/management/commands/runserver.py", line 16, in <module>
from django.db.migrations.executor import MigrationExecutor File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/db/migrations/executor.py", line 7, in <module>
from .loader import MigrationLoader File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/db/migrations/loader.py", line 10, in <module>
from django.db.migrations.recorder import MigrationRecorder File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/db/migrations/recorder.py", line 12, in <module>
class MigrationRecorder(object): File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/db/migrations/recorder.py", line 26, in MigrationRecorder
class Migration(models.Model): File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/db/migrations/recorder.py", line 27, in Migration
app = models.CharField(max_length=255) File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/db/models/fields/__init__.py", line 1072, in __init__
super(CharField, self).__init__(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/db/models/fields/__init__.py", line 166, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/conf/__init__.py", line 55, in __getattr__
self._setup(name) File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module) File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name) File "/var/www/Web-Interaction-APP/settings.py", line 8, in <module>
application = get_wsgi_application() File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup() File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/__init__.py", line 17, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/conf/__init__.py", line 55, in __getattr__
self._setup(name) File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module) File "/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg/django/conf/__init__.py", line 120, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.") django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
I have also tried to change my manage.py and wsgi.py. My folder is:
Web-Interaction-APP
-manage.py
-seetings.py
*apache(folder)
-wsgi.py
*project(folder)
in my manage.py:
#!/usr/bin/env python
#This file runs the server for this application from command line.
import os, sys
#Executes the code in the following condition if the program is run directly.
#(Source: http://stackoverflow.com/questions/419163/what-does-if-name-main-do)
if __name__ == "__main__":
#Refers to the path of this django project's settings module.
#(DJANGO_SETTINGS_MODULE is an environment variable to module import path.)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
from django.core.management import execute_from_command_line
#Executes the django project.
execute_from_command_line(sys.argv)
In my wsgi.py:
import os, sys
# Calculate the path based on the location of the WSGI script.
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append(project)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Web-Interaction-APP.settings")
# Add the path to 3rd party django application and to django itself.
sys.path.append('/home/zhaojf1')
os.environ['DJANGO_SETTINGS_MODULE'] = '10.231.52.XX.apache.override'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Maybe in your settings file, you are setting the SECRET_KEY using a ENV variable, open a shell and just:
export SECRET_KEY='test_key'
Then, try to run your server again.
This error is common when your DJANGO_SETTINGS_MODULE path is incorrect.
When you run python manage.py runserver 8000 you are using manage.py which is settings your DJANGO_SETTINGS_MODULE to settings. It doesn't appear that you have a settings.py in your root directory, so this line in manage.py:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
should become:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Web-Interaction-APP.settings")
as you have in your wsgi.py file.
This question already has an answer here:
ImportError: cannot import name get_path_info
(1 answer)
Closed 7 years ago.
In Heroku, I upload my Django application, and it works well with the following code in wsgi.py:
from django.core.wsgi
import get_wsgi_application
#from dj_static import Cling
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hellodjango.settings")
application = get_wsgi_application()
#application = Cling(get_wsgi_application()
But when I uncomment the commented lines my application crashes in Heroku.
Also when I import dj_static in the Python interpreter I get the following error:
>>> from dj_static import Cling
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/dj_static-0.0.6-py2.7.egg/dj_static.py", line 7, in <module>
from django.contrib.staticfiles.handlers import StaticFilesHandler as DebugHandler
File "/usr/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 13, in <module>
from django.contrib.staticfiles.views import serve
File "/usr/lib/python2.7/dist-packages/django/contrib/staticfiles/views.py", line 16, in <module>
from django.views import static
File "/usr/lib/python2.7/dist-packages/django/views/static.py", line 98, in <module>
template_translatable = ugettext_noop("Index of %(directory)s")
File "/usr/lib/python2.7/dist-packages/django/utils/translation/__init__.py", line 60, in gettext_noop
return _trans.gettext_noop(message)
File "/usr/lib/python2.7/dist-packages/django/utils/translation/__init__.py", line 47, in __getattr__
if settings.USE_I18N:
File "/usr/lib/python2.7/dist-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/usr/lib/python2.7/dist-packages/django/conf/__init__.py", line 46, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting USE_I18N, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Why it this happening? Just by importing dj_static these errors occur.
Try to install dj-static file.
* Check this https://www.versioneye.com/python/dj-static/0.0.6
i found an error while running webservice on local
Traceback (most recent call last):
File "D:\Projects\wamp\www\mysite_livebackupcode\django-apps\mysite\account\views.py", line 3, in <module>
from django.views.decorators.csrf import csrf_exempt
File "C:\Python27\Lib\site-packages\django\views\decorators\csrf.py", line 1, in <module>
from django.middleware.csrf import CsrfViewMiddleware, get_token
File "C:\Python27\Lib\site-packages\django\middleware\csrf.py", line 14, in <module>
from django.utils.cache import patch_vary_headers
File "C:\Python27\Lib\site-packages\django\utils\cache.py", line 26, in <module>
from django.core.cache import get_cache
File "C:\Python27\Lib\site-packages\django\core\cache\__init__.py", line 69, in <module>
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "C:\Python27\Lib\site-packages\django\conf\__init__.py", line 54, in __getattr__
self._setup(name)
File "C:\Python27\Lib\site-packages\django\conf\__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either
define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
can anybody please help me to get out of this stuff.
thanks in advance
You can set environment variable in linux for example:
export DJANGO_SETTINGS_MODULE=myproject.settings
It should help you.
I have a script, which should run once per day by crontab. That works fine on my desktop. But when I try to run it on a virtualenv on my RPi, I get this error:
Traceback (most recent call last):
File "mailalert.py", line 7, in <module>
from django.contrib.auth.models import User
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/contrib/auth/__init__.py", line 5, in <module>
from django.middleware.csrf import rotate_token
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/middleware/csrf.py", line 16, in <module>
from django.utils.cache import patch_vary_headers
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/utils/cache.py", line 26, in <module>
from django.core.cache import get_cache
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/core/cache/__init__.py", line 70, in <module>
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/conf/__init__.py", line 46, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
It looks like I cant use:
from django.contrib.auth.models import User
What is the problem?
DJANGO_SETTINGS_MODULE
You need to configure the DJANGO_SETTINGS_MODULE environment variable in your mailalert.py script, prior to importing Django code.
Here's how you could do it:
#!/usr/bin/env python
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "benchmarks.settings")
# Do you thing now.
Virtualenv
Note that you code is probably not running inside a virtualenv right now, as made evidenced by the package paths (/usr/local/lib isn't your virtualenv):
"/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/contrib/auth/__init__.py"
Installed pyes recently , but when i tired it in the python shell it is giving the error,
Can any one please help me out in this regard:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pyes-0.19.1-py2.7.egg/pyes/__init__.py", line 41, in <module>
from .djangoutils import *
File "/usr/local/lib/python2.7/dist-packages/pyes-0.19.1-py2.7.egg/pyes/djangoutils.py", line 6, in <module>
from django.db import models
File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 11, in <module>
if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 52, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 45, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
I found that this issue can be "worked around" by simply performing the following before running the script in Terminal
export DJANGO_SETTINGS_MODULE=default.settings
After running that code the script worked exactly the way it was supposed to!