找不到部署Heroku的WSGI模块
尝试使用此一个>教程。出现 ModuleNotFoundError:没有名为 radio.wsgi的模块
消息。
Trying to deploy my app with this tutorial. Have a ModuleNotFoundError: No module named 'radio.wsgi'
message.
2019-08-21T08:08:21.409841+00:00 app[web.1]: __import__(module)
2019-08-21T08:08:21.409849+00:00 app[web.1]: ModuleNotFoundError: No module named 'radio.wsgi'
2019-08-21T08:08:21.409960+00:00 app[web.1]: [2019-08-21 08:08:21 +0000] [10] [INFO] Worker exiting (pid: 10)
2019-08-21T08:08:21.441211+00:00 app[web.1]: [2019-08-21 08:08:21 +0000] [4] [INFO] Shutting down: Master
2019-08-21T08:08:21.441415+00:00 app[web.1]: [2019-08-21 08:08:21 +0000] [4] [INFO] Reason: Worker failed to boot.
在其他一些问题中,人们建议使用 python manage.py run_gunicorn
但我有个未知命令:'run_gunicorn'
In some other questions people recomends python manage.py run_gunicorn
but I have Unknown command: 'run_gunicorn'
Procfile:
web: gunicorn radio.wsgi --log-file -
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'radio.settings')
application = get_wsgi_application()
仅在那些文件中提到了WSGI。
In only those files WSGI is mentioned.
requirements.txt
requirements.txt
dj-database-url==0.5.0
Django==2.2.4
gunicorn==19.9.0
lxml==4.4.1
psycopg2-binary==2.8.3
pytz==2019.2
sqlparse==0.3.0
whitenoise==4.1.3
这是项目结构
├── radio
│ ├── db.sqlite3
│ ├── manage.py
│ ├── player
│ ├── radio
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── setup.py
│ └── static
├── README.md
├── .gitignore
├── requirements.txt
├── runtime.txt
└── Procfile
Heroku期望 Procfile
位于项目根目录中。如果 manage.py
也在项目根目录中,则部署Django应用也是最简单的。例如,如果您的项目布局为:
Heroku expects Procfile
to be in the project root. It is easiest to deploy a Django app if manage.py
is in the project root as well. For example, if your project layout was:
├── db.sqlite3
├── manage.py
├── player
├── radio
│ ├── __init__.py
│ ├── __pycache__
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── setup.py
├── static
├── README.md
├── .gitignore
├── requirements.txt
├── runtime.txt
└── Procfile
然后您可以运行:
web: gunicorn radio.wsgi
在您的情况下,您的Django项目位于 radio
Directoy。如果您不想更改项目布局,则需要在Python路径中添加 radio
以便python导入起作用:
In your case, your Django project is in the radio
directoy. If you don't want to change the project layout, then you need to add radio
to the python path so that python imports work:
web: gunicorn --pythonpath radio radio.wsgi