简体   繁体   中英

Python Anywhere Django App Import Error

I'm getting the following import error when trying to run a django app on Python Anywhere:

Error running WSGI application
ImportError: No module named 'chamberlin.settings'
  File "/var/www/mikechamberlin_pythonanywhere_com_wsgi.py", line 58, in <module>
    application = get_wsgi_application()

I have checked both my WSGI config file and my directory structure and both seem to be correct.

WSGI File:

import os
import sys

path = '/home/mikechamberlin/chamberlin'
if path not in sys.path:
    sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'chamberlin.settings'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Tree:

mikechamberlin
├── ...
├── chamberlin
    ├── __init__.py
    ├── chamberlin
    │   ├── __init__.py
    │   ├── admin.py
    │   ├── private_settings.py
    │   ├── settings.py
    │   ├── static
    ...

Can anyone see something I'm not seeing? I've already searched here and read the ImportError help messages on PythonAnywhere, but my things seem to be named correctly. Importing from the console works, but I still get this error when trying to run the application.

Much Appreciated.

I've had the same struggle while deploying on pythonanywhere before but, I try all possible combinations to exposing the location of my settings.py.

import os 
import sys

path = '/home/garapkan/Garap/garap_v2/'
print(path)

if path not in sys.path:
sys.path.insert(0, path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

from django.core.wsgi import get_wsgi_application
from django.contrib.staticfiles.handlers import StaticFilesHandler

application = StaticFilesHandler(get_wsgi_application())

and make sure the path is in the first oreder of sys.path insert it at first row instead of append it. read @glenn comment on question. and I found it works for me. Hope this way will work for others too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM