【问题标题】:Can't deploy Django on Heroku无法在 Heroku 上部署 Django
【发布时间】:2020-07-11 21:32:40
【问题描述】:

我在本地主机上测试并运行了一个名为“django_project”的项目。
现在我已经尝试在 Heroku 部署我的应用程序(真的尝试了一切),但出现错误提示:

heroku[web.1]: Starting process with command `gunicorn django_projcet.wsgi  
heroku[web.1]: State changed from starting to crashed  
heroku[web.1]: Process exited with status 3   
app[web.1]: ModuleNotFoundError: No module named 'django_projcet'      
app[web.1]: [INFO] Worker exiting (pid: 10)     
app[web.1]: [INFO] Shutting down: Master      
app[web.1]: [4] [INFO] Reason: Worker failed to boot.

我的项目树:

过程文件:

web: gunicorn django_projcet.wsgi

wsgi.py:

"""
WSGI config for django_project project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()

requirements.txt:

boto3==1.12.31
botocore==1.15.31
certifi==2019.11.28
chardet==3.0.4
dj-database-url==0.5.0
Django==3.0.4
django-crispy-forms==1.9.0
django-storages==1.9.1
django-heroku==0.3.1
docutils==0.15.2
gunicorn==20.0.4
idna==2.8
jmespath==0.9.5
Pillow==7.0.0
psycopg2==2.7.7
python-dateutil==2.8.1
pytz==2019.3
requests==2.22.0
s3transfer==0.3.3
six==1.14.0
urllib3==1.25.8
whitenoise==5.0.1

【问题讨论】:

    标签: python django heroku


    【解决方案1】:

    要在 Heroku 中部署 django 应用程序,您需要 3 个文件

    1. runtime.txt
    2. 过程文件
    3. requirements.txt

    在 runtime.txt 中提及你的 python 版本

    python-3.7.8
    

    在 Procfile 中

    web: gunicorn django_project.wsgi
    

    对于 requirements.txt,你可以使用

    pip freeze > requirements.txt
    

    你的 Procfile 有错误,你写了 web: gunicorn django_projcet.wsgi

    改为web: gunicorn django_project.wsgi

    您的项目名称与 Procfile 中的不匹配

    【讨论】:

    • 你写了和我写的一样的 procfile 配置.. 它不工作
    • @Moshe 请在 Procfile 中检查你的项目名称,这是错误的
    猜你喜欢
    • 2019-11-19
    • 2013-08-22
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    • 2013-03-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-12
    相关资源
    最近更新 更多