使用 git 推送将 django 应用程序部署到 heroku 时出现无法识别的错误

Unrecognised error when deploying django app to heroku with git push

我有一个具有以下文件结构的 Django 应用程序

- project_name
        (settings, __init__, urls, asgi, wsgi ... *.py)
- manage.py
- app_name
        - templates
                (template files)
        - static
                (just some static files)
        (urls, views, apps, models __init__ and the other usual files within django app *.py)

- requirements.txt

我认为我在顶级目录(包含 project_name 和 app_name 子目录)中有 运行 所有必要的命令

  1. git init
  2. heroku git:remote -a (heroku_app_name)
  3. git add .
  4. git commit -am "this is a commit message"

然后错误出现在 git push heroku master 中,日志如下:

remote: -----> Python app detected
remote: -----> Installing python-3.6.12
remote: -----> Installing pip 20.1.1, setuptools 47.1.1 and wheel 0.34.2
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote:        Collecting django
remote:          Downloading Django-3.1.3-py3-none-any.whl (7.8 MB)
remote:        Collecting django-heroku
remote:          Downloading django_heroku-0.3.1-py2.py3-none-any.whl (6.2 kB)
remote:        Collecting sqlparse>=0.2.2
remote:          Downloading sqlparse-0.4.1-py3-none-any.whl (42 kB)
remote:        Collecting asgiref<4,>=3.2.10
remote:          Downloading asgiref-3.3.1-py3-none-any.whl (19 kB)
remote:        Collecting pytz
remote:          Downloading pytz-2020.4-py2.py3-none-any.whl (509 kB)
remote:        Collecting whitenoise
remote:          Downloading whitenoise-5.2.0-py2.py3-none-any.whl (19 kB)
remote:        Collecting psycopg2
remote:          Downloading psycopg2-2.8.6.tar.gz (383 kB)
remote:        Collecting dj-database-url>=0.5.0
remote:          Downloading dj_database_url-0.5.0-py2.py3-none-any.whl (5.5 kB)
remote:        Building wheels for collected packages: psycopg2
remote:          Building wheel for psycopg2 (setup.py): started
remote:          Building wheel for psycopg2 (setup.py): finished with status 'done'
remote:          Created wheel for psycopg2: filename=
remote:          Stored in directory: /tmp/pip-ephem-wheel-cache-#############
remote:        Successfully built psycopg2
remote:        Installing collected packages: sqlparse, asgiref, pytz, django, whitenoise, psycopg2, dj-database-url, django-heroku
remote:        Successfully installed asgiref-3.3.1 dj-database-url-0.5.0 django-3.1.3 django-heroku-0.3.1 psycopg2-2.8.6 pytz-2020.4 sqlparse-0.4.1 whitenoise-5.2.0
remote: -----> Discovering process types
remote:        Procfile declares types -> (none)
remote:
remote: -----> Compressing...
remote:        Done: 53M
remote: -----> Launching...
remote:
remote:  !     Push failed due to an unrecognized error, and we've been notified.
remote:
remote:  !     Please try pushing again.
remote:  !     If the problem persists, see http://help.heroku.com/ and provide Request ID ###############
remote:
remote:
remote: Verifying deploy...
remote:
remote: !       Push rejected to (heroku_app_name).
remote:
To https://git.heroku.com/(heroku_app_name).git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/(heroku_app_name).git'

我决定禁用 heroku config:set DISABLE_COLLECTSTATIC=1 收集静态信息,因为它会带来更多错误,但我认为这不是问题所在。

我正在 运行正在使用最新版本的 Windows 10 Home,当时有人问这个问题。

您似乎没有为 Heroku 部署包含 Procfile。按照以下指南创建 Procfile 并设置:

  1. 安装 gunicorn 库,它是 Django 和 Flask 应用程序的生产 Web 服务器
pip install gunicorn
  1. gunicorn 添加到您的 requirements.txt 文件。
pip freeze -r requirements.txt
  1. 在应用程序的根目录中创建一个名为 Procfile 的新文件。这是创建 Procfile:
  2. 后的文件结构
- project_name
        (settings, __init__, urls, asgi, wsgi ... *.py)
- manage.py
- app_name
        - templates
                (template files)
        - static
                (just some static files)
        (urls, views, apps, models __init__ and the other usual files within django app *.py)

- requirements.txt
- Procfile
  1. 将以下行添加到 Procfile:
web: gunicorn projectname.wsgi

注意:将 projectname.wsgi 行中的“项目名称”替换为您的项目名称

  1. Re-deploy 申请

参考:https://devcenter.heroku.com/articles/django-app-configuration