Reputation: 10797
I've problems running the simplest django project within GAE.
After running django-admin startproject myproj
(Using django 1.4 from Google SDK), the folder hierarchy look as:
+ myproj (root folder of project) - manage.py + myproj (a sub folder for the project files) - __init__.py - settings.py - urls.py - wsgi.py
I then add the usual app.yaml to the root folder - that is to the same folder where manage.py is.
application: u-pavarotti
version: 1
runtime: python27
api_version: 1
threadsafe: true
libraries:
- name: django
version: "1.4"
builtins:
- django_wsgi: on
syncdb, dbshell, shell ... works great. Even manage.py runserver
works file. However, trying to run dev_appserver
fails. The exception I get is:
ImportError: Could not import settings 'settings'
.
Well, taking a look at google/appengine/ext/django/main (which django_wsgi
is basically setting a URL handler for .* to the google.appengine.ext.django.main.app) is appears that it expect to find settings in the python path. But without doing anything, the module to import is myproj.settings
(as myproj isn't in the path).
Now, adding .../myproj/myproj (the lower folder) to the PYTHONPATH solve everything on my dev machine, but as I have no control on the search path on the GAE deployment - this solution won't work.
I can move all files, or just settings.py up to the upper myproj, or move app.yaml down (kinda same thing), but it requires various changes form the default genereated settings.py - and I don't this is the way to go. Alternatively, I can write my own handler, which will instantiate django.core.handlers.wsge.WSGIHandler (old tutorials used to do that) - again, seems against the intention of at least the creators of the 'builtin' attribute of app.yaml.
I wonder how everyone else is solving this issue, and what is the right thing to do.
Upvotes: 1
Views: 1740
Reputation: 599490
You can declare the environment variable DJANGO_SETTINGS_MODULE
in your app.yaml:
env_variables:
DJANGO_SETTINGS_MODULE: 'myproj.settings'
Upvotes: 3