Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...