首页 > 解决方案 > Django,Heroku,DisallowedHost 在 / 但主机在允许的主机列表中

问题描述

我有一个部署到 Heroku 的 Django 应用程序,但是当我尝试访问它时,我被禁止,主机错误说 Heroku 主机 URL 不在允许的主机中,但它实际上是。

错误

Invalid HTTP_HOST header: 'scr-rivendell.herokuapp.com'. You may need to add 'scr-rivendell.herokuapp.com' to ALLOWED_HOSTS.

设置:

ALLOWED_HOSTS = ['localhost', '127.0.0.1:8000', 'https://scr-rivendell.herokuapp.com/']

我检查了外壳以确保我是对的:

>>> import django
>>> django.conf.settings.ALLOWED_HOSTS
['localhost', '127.0.0.1:8000', 'https://scr-rivendell.herokuapp.com/']

标签: djangoheroku

解决方案


诸如http://prhttps://之类的 Url Scheme 不是主机地址的一部分。

将您的 ALLOWED_HOSTS 更新到下面应该可以。

ALLOWED_HOSTS = ['localhost', '127.0.0.1:8000', 'scr-rivendell.herokuapp.com']

推荐阅读