Gunicorn/Django, ImportError: No module named application.wsgi

别等时光非礼了梦想. 提交于 2019-12-10 09:57:07

问题


I'm trying to deploy a Django app using Heroku, but I'm running into the following error: "ImportError: No module named myproject.wsgi".

My project is configured as such:

my-project
│   Procfile
│   requirements.txt
│   runtime.txt
│   README.md
│
├───myproject
│   │   db.sqlite3
│   │   django
│   │   django._file_
│   │   import
│   │   manage.py
|   |
│   ├───myproject
|   |   |    wsgi.py
|   |   |    settings.py
|   |   |    urls.py
|   |   |    _init_.py
|   |   |
|   |   ├───_pycache_
|   | 
│   ├───venv
...

My wgsi.py file is configured as such:

import os
import signal
import sys
import traceback
import time

from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

application = get_wsgi_application()
application = DjangoWhiteNoise(application)

My Procfile contains the following:

web: gunicorn myproject.wsgi:application --log-file -

Why is this producing an error?


回答1:


It seems your running directory is the outermost my-project. Try to change your WSGI application path like gunicorn myproject.myproject.wsgi:application --log-file - and see if the error changes.

I think putting your project in the root directory (i.e. removing the first myproject directory and putting your manage.py in my-project directory) is a requirement for Heroku and will fix your problem.




回答2:


Extending above answer I tried my WSGI path to gunicorn myproject.myproject.wsgi:application --log-file - and yes error changed now it says ImportError: No module named myproject.settings. To solve this I changed my wsgi file.

FROM:

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')

TO:

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.myproject.settings')

It woked like a charm for me!



来源:https://stackoverflow.com/questions/47616586/gunicorn-django-importerror-no-module-named-application-wsgi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!