Reputation: 4977
I'm trying to get a "Hello World" Django 1.5 app working with Google App Engine. Everything works perfectly if my directory structure is like this:
.
| ____myproj
| |______init__.py
| |____app.yaml
| |____settings.py
| |____urls.py
| |____views.py
| |____wsgi.py
|____manage.py
However, as soon as I add a new "app" to the project (using manage.py startapp app1
), I start getting ImportErrors.
This is the ideal structure I want:
.
|____app1
| |______init__.py
| |____admin.py
| |____models.py
| |____tests.py
| |____views.py
|____myproj
| |______init__.py
| |____app.yaml
| |____settings.py
| |____urls.py
| |____views.py
| |____wsgi.py
|____manage.py
To enable "app1", I modify the INSTALLED_APPS in my settings.py to:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app1',
)
Notice I added "app1" to INSTALLED_APPS. As soon as I do that, GAE starts complaining: ImportError: No module named app1.
What am I doing wrong? If I try to run the app with pure Django (not AppEngine), everything is fine. But if I try to run it with AppEngine, it doesn't like that "app1" I added to my INSTALLED_APPS. Removing that line from INSTALLED_APPS makes everything run again with no errors in AppEngine!
Note: my PYTHONPATH has '/Users/mel/Sites/myproj/myproj' followed by all the standard google app engine paths.
Upvotes: 1
Views: 245
Reputation: 4977
Solved it myself! This turned out to be a configuration error on my part. When you have a Django project with multiple apps, the app.yaml file needs to be "outside" the project directory. In other words, the app.yaml file needs to be sitting next to manage.py
instead of next to settings.py
. That way, all the apps in your project will automatically get included in the PYTHONPATH.
Note: You may also need to add the following 2 lines to app.yaml:
env_variables:
DJANGO_SETTINGS_MODULE: 'myproj.settings'
Upvotes: 2
Reputation: 55197
This is not typically how a django project is organized.
Right now, your app is living inside the project. Those should instead be living side by side.
Assuming your project is named proj
and your app app
, this is what your directory layer should look like:
.
├── manage.py
├── app
│ ├── __init__.py
│ ├── admin.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
└── proj
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
Upvotes: 0