Reputation: 6013
I am trying to set up a Django app on Pythonanywhere — I've managed to figure out Bitbucket and clone the code in — I deleted the files in the directory that was provided for me — but can't get it to work.
I've done 'syncdb', then when I go to what I think is the correct URL for the app, I keep getting "Unhandled exception" — The error is that it can't find 'portfolio.settings' in an import (portfolio is the name of the app)
I also have no idea what to put for MEDIA_ROOT and STATIC_DIRS — these should be, as far as I know, full paths, not relative.
I'm a Django newbie, and this is proving rather overwhelming, to get the app, which functions fine locally, deployed. Any help much provided (I haven't found the Pythonanywhere forums — which don't seem indexed -- or help all that helpful, I'm afraid)
I also thought: why don't I let Pythonanywhere set up a blank project for me, but again, I don't know how to handle STATIC_DIRS and MEDIA_ROOT, and I don't really know how to make my project fit their setup.
Thanks for any help.
Upvotes: 7
Views: 3410
Reputation: 16071
For anyone else that runs into similar issues: import errors in web applications are typically to do with your sys.path
not being correctly configured. Check your WSGI file (on PythonAnywhere, you can find it on your web tab. Other hosts may do things differently).
Example:
/home/myusername/myproject/
is the project folder/home/myusername/myproject/my_cool_app/
is one of your app folders/home/myusername/myproject/myproject/settings.py
is the settings file locationYour WSGI file should have:
sys.path.append('/home/myusername/myproject')
# ...
DJANGO_SETTINGS_MODULE = 'myproject.settings'
And your settings.py should have
INSTALLED_APPS = (
#...
'my_cool_app'
Everything has to line up so that the dot-notation names of your app in INSTALLED_APPS
and your DJANGO_SETTINGS_MODULE
environment variable will import correctly, relative to the folder you add to sys.path.
So in the example above, you could conceivably do:
# wsgi file
sys.path.append('/home/myusername')
DJANGO_SETTINGS_MODULE = 'myproject.myproject.settings'
# settings.py
INSTALLED_APPS = 'myproject.my_cool_app'
But don't do that, it's overcomplicated.
PS there's a detailed guide to sys.path and import issues for pythonanywhere in the docs.
Upvotes: 5