简体   繁体   English

在 Heroku 服务器上上传 Django 项目

[英]Uploading a Django project on Heroku Server

I uploaded my Django project to Heroku and I get this error message on the browser as shown on the screenshot我将我的 Django 项目上传到 Heroku,我在浏览器上收到此错误消息,如屏幕截图所示

在此处输入图像描述

But when I check the log on the admin I see this message below:但是当我检查管理员的日志时,我看到下面这条消息:

2019-05-14T21:26:26.138333+00:00 app[web.1]: bash: gunicorn: command not found 2019-05-14T21:26:26.138333+00:00 app[web.1]: bash: gunicorn: command not found

But gunicorn is included in my requirements.txt file:但是gunicorn包含在我的requirements.txt文件中:

dj-database-url==0.5.0
Django==2.2.1
django-heroku==0.3.1
gunicorn==19.9.0
psycopg2==2.8.2
pytz==2019.1
sqlparse==0.3.0
whitenoise==4.1.2

I also have a Pipfile and Pipfile.lock .我还有一个PipfilePipfile.lock

Why can't Heroku find gunicorn ?为什么 Heroku 找不到gunicorn

Generally speaking, you should use either requirements.txt or Pipfile and Pipfile.lock .一般来说,您应该使用requirements.txtPipfilePipfile.lock They do roughly the same thing, but work with different tooling.他们做大致相同的事情,但使用不同的工具。

Pipfile and Pipfile.lock are a newer standard. PipfilePipfile.lock是较新的标准。 If they are present, Heroku installs dependencies using Pipenv .如果它们存在,Heroku 会使用Pipenv安装依赖项。 In this case the requirements.txt file is ignored.在这种情况下, requirements.txt文件将被忽略。

You should either你应该

  1. Choose to use Pipenv.选择使用 Pipenv。

    1. Your requirements may already be listed in the Pipfile and Pipfile.lock , but run pipenv install -r requirements.txt locally just to be sure.您的要求可能已经列在PipfilePipfile.lock中,但为了确定起见,请在本地运行pipenv install -r requirements.txt
    2. Delete your requirements.txt with git rm requirements.txt .使用git rm requirements.txt requirements.txt
    3. Commit this change, eg git commit -m 'Switch from pip to Pipenv' .提交此更改,例如git commit -m 'Switch from pip to Pipenv'
    4. Push to Heroku.推送到 Heroku。
  2. Choose to use pip .选择使用pip

    1. Read your Pipfile to see if there's anything in there you might need.阅读你的Pipfile看看里面是否有你可能需要的东西。 This file does more than just list dependencies.该文件不仅仅列出依赖项。

      For example, your Pipfile may specify a required Python version like python_version = '3.7' in the [requires] section.例如,您的Pipfile可能会在[requires]部分指定所需的 Python 版本,如python_version = '3.7' This can't be represented in requirements.txt , so you'll need to create a runtime.txt file to specify your Python version.这不能在requirements.txt中表示,因此您需要创建一个runtime.txt文件来指定您的 Python 版本。

      You might also want to create a second requirements file for development dependencies.您可能还想为开发依赖项创建第二个需求文件。

    2. Delete the Pipfile and Pipfile.lock with git rm Pipfile Pipfile.lock .使用git rm Pipfile Pipfile.lock删除PipfilePipfile.lock

    3. Commit, eg git commit -m 'Revert from Pipenv to pip .提交,例如git commit -m 'Revert from Pipenv to pip

    4. Push to Heroku.推送到 Heroku。

I uploaded my Django project to Heroku and I get this error message on the browser as shown on the screenshot我将我的 Django 项目上传到 Heroku,我在浏览器上收到此错误消息,如屏幕截图所示

在此处输入图片说明

But when I check the log on the admin I see this message below:但是当我检查管理员的日志时,我看到以下消息:

2019-05-14T21:26:26.138333+00:00 app[web.1]: bash: gunicorn: command not found 2019-05-14T21:26:26.138333+00:00 app[web.1]: bash: gunicorn: 命令未找到

But gunicorn is included in my requirements.txt file:但是gunicorn包含在我的requirements.txt文件中:

dj-database-url==0.5.0
Django==2.2.1
django-heroku==0.3.1
gunicorn==19.9.0
psycopg2==2.8.2
pytz==2019.1
sqlparse==0.3.0
whitenoise==4.1.2

I also have a Pipfile and Pipfile.lock .我也有一个PipfilePipfile.lock

Why can't Heroku find gunicorn ?为什么 Heroku 找不到gunicorn

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM