【问题标题】:deploy Django2 on heroku , but can not open the webpage in browsers在heroku上部署Django2,但无法在浏览器中打开网页
【发布时间】:2018-11-16 05:06:29
【问题描述】:

我在 python 上做了一个 django 项目,并将其推送到 heroku,但是当我尝试使用

访问它时
https://desolate-oasis-71960.herokuapp.com

浏览器无法加载。

我在python3上使用django2.1.3,这里是我的settings.py:

import os
import django_heroku 

# Build paths inside the project like this:os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
--snip-

# Activate Django-Heroku.
django_heroku.settings(locals())

#setting Heroku
cwd = os.getcwd()
if cwd == '/app' or cwd[:4] == '/tmp':
    import dj_database_url
    DATABASES= {
    'default': dj_database_url.config(default='postgres://localhost')
}

    SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO','https')

    #ALLOWED_HOSTS = ['*']

    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
    STATIC_URL = '/static/'
    STATICFILES_DIRS = (
    os.path.join(BASE_DIR,'static'),
)

但是我将项目推送到heroku后,我无法打开网页,然后我运行命令:heroku logs,这是日志:

 2018-11-16T03:47:55.000000+00:00 app[api]: Build      succeeded
 2018-11-16T03:48:48.803513+00:00 heroku[router]: at=error code=H14      

 desc="No web processes running" method=GET path="/" 
 host=desolate-oasis-71960.herokuapp.com 
 request_id=703f8297-76f6-4434-9fcc-805c059fd3d8  
 fwd="202.119.45.10" dyno= connect= service=status=503    
 bytes=protocol=https

我也尝试使用命令在本地加载它

heroku local

命令窗口总是这样显示:

2:52:27 PM web.1 |  [2018-11-16 14:52:27 +0800] [1950] [INFO] Starting
gunicorn 19.9.0

2:52:27 PM web.1 |  [2018-11-16 14:52:27 +0800] [1950] [INFO] Listening     
at: http://0.0.0.0:5000 (1950)

2:52:27 PM web.1 |  [2018-11-16 14:52:27 +0800] [1950] [INFO] Using worker: sync

2:52:27 PM web.1 |  [2018-11-16 14:52:27 +0800] [1953] [INFO] Booting   
worker with pid: 1953

我需要按“control”+“C”退出

请帮帮我

【问题讨论】:

  • 你在 heroku 日志上得到了什么?您可以通过运行 heroku logs --tail 查看 heroku 日志
  • 你的 Procfile 中有什么?

标签: django python-3.x heroku


【解决方案1】:

settings.py:

ALLOWED_HOSTS = ['desolate-oasis-71960.herokuapp.com']

【讨论】:

    【解决方案2】:

    谢谢,我已经通过在终结器中使用命令重新构建 Procfile 解决了这个问题:

    touch .Procfile
    

    我删除了我的 .git 文件(必须删除这个文件), 然后通过命令重新初始化.git文件

    git init 
    

    它奏效了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      • 1970-01-01
      • 2019-11-27
      • 2018-04-01
      • 2019-12-14
      相关资源
      最近更新 更多