WSGI cannot be loaded as Python module

python django python-2.7 django-wsgi

1107 просмотра

1 ответ

I'm getting this error

'path-to/wsgi.py' cannot be loaded as Python module.

I've never had it before having loaded many Python / Django projects by

mkdir directory
cd directory
virtualenv env 
env/bin/pip install -r requirements.txt 

Then FTP in the files and then

env/bin/python manage.py migrate
env/bin/python manage.py collectstatic
env/bin/python manage.py createsuperuser

Today it isn't working. I've read a number of posts with similar issues but they seem to be due to different versions of python. Mine aren't. Any ideas.

EDIT Traceback added

 mod_wsgi (pid=8982): Target WSGI script '/var/www/mattscott/mainapp/wsgi.py' cannot be loaded as Python module.
 mod_wsgi (pid=8982): Exception occurred processing WSGI script '/var/www/mattscott/mainapp/wsgi.py'.
 Traceback (most recent call last):
   File "/var/www/mattscott/mainapp/wsgi.py", line 16, in <module>
     application = get_wsgi_application()
   File "/var/www/mattscott/env/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
     django.setup(set_prefix=False)
   File "/var/www/mattscott/env/lib/python2.7/site-packages/django/__init__.py", line 22, in setup
     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
   File "/var/www/mattscott/env/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
     self._setup(name)
   File "/var/www/mattscott/env/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
     self._wrapped = Settings(settings_module)
   File "/var/www/mattscott/env/lib/python2.7/site-packages/django/conf/__init__.py", line 97, in __init__
     mod = importlib.import_module(self.SETTINGS_MODULE)
   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
     __import__(name)
   ImportError: No module named mainapp.settings
Автор: HenryM Источник Размещён: 19.09.2019 03:53

Ответы (1)


0 плюса

Решение

Found a solution but I expect it is the symptom of something else wrong (I'm hoping Graham will explain).

I've added:

path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if path not in sys.path:
    sys.path.append(path)

to wsgi.py

Автор: HenryM Размещён: 15.05.2017 06:29
Вопросы из категории :
32x32