努力使用我用于heroku 工作的Procfile。尝试学习如何建立和运行一个基本的 Django 网站,并从头开始构建一些东西。我在 PC 上使用 Windows 来进行修改,因此决定使用 waitress,但也许 Gunicorn 会更容易?
如果我无法解决这个问题,我只会使用 heroku 的模板并从中构建,但我不想放弃迄今为止所做的事情。
这是我的目录结构。
Root +---
.git
Include
Lib
Scripts
Scripts
Static
tcl
src +---
� db.sqlite3
� manage.py
�
+---alex1
� � forms.py
� � settings.py
� � urls.py
� � wsgi.py
� � __init__.py
� �
� +---__pycache__
� settings.cpython-36.pyc
� urls.cpython-36.pyc
� wsgi.cpython-36.pyc
� __init__.cpython-36.pyc
�
+---profiles
� admin.py
� apps.py
� forms.py
� models.py
� tests.py
� views.py
� __init__.py
�
+---migrations
� � 0001_initial.py
� � 0002_profile_description.py
� � 0003_auto_20170905_1654.py
� � 0004_auto_20170905_1659.py
� � __init__.py
� �
� +---__pycache__
� 0001_initial.cpython-36.pyc
� 0002_profile_description.cpython-36.pyc
� 0003_auto_20170905_1654.cpython-36.pyc
� 0004_auto_20170905_1659.cpython-36.pyc
� __init__.cpython-36.pyc
�
+---templates
� base.html
� contact.html
�
+---__pycache__
admin.cpython-36.pyc
forms.cpython-36.pyc
models.cpython-36.pyc
views.cpython-36.pyc
__init__.cpython-36.pyc
我收到的错误是这样的
2017-10-08T09:33:38.547463+00:00 app[web.1]: There was an exception (ModuleNotFoundError) importing your module.
2017-10-08T09:33:38.547464+00:00 app[web.1]: It had these arguments:
2017-10-08T09:33:38.547464+00:00 app[web.1]: 1. No module named 'profiles'
这是我的 procfile。
web: waitress-serve --port=$PORT profiles.wsgi:application
谢谢大家 - 非常感谢您的帮助
最佳答案
首先,您的 wsgi.py 文件不在 src/profiles 内,而是在 src/alex1 内。另外,waitress 找不到您的应用程序配置文件,因为它不在 python 路径中。我不知道女服务员是否有一个参数可以将东西添加到 PYTHONPATH 中(例如gunicorn --pythonpath),但无论如何你可以这样做:
web: PYTHONPATH=$(pwd)'/src' waitress-serve --port=$PORT alex1.wsgi:application
我和女服务员一起工作过,我看不出使用它代替gunicorn有什么改进。有些人说它的性能更高,但根据我的经验,它只是使用起来更烦人。
关于python - Heroku 的 Procfile 无法正常工作 - 使用 Waitress 的 Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46629641/