django: You may need to add ‘localhost‘ to ALLOWED_HOSTS

参考:https://blog.csdn.net/qq_21744873/article/details/87857279

python manage.py runserver后页面访问失败,提示:

DisallowedHost at /admin/

Invalid HTTP_HOST header: 'localhost:8000'. You may need to add 'localhost' to ALLOWED_HOSTS.

解决方法:

这里项目名称为test

打开test/test/settings.py配置文件,找到ALLOWED_HOSTS配置项

正常情况下,该配置项默认为空:ALLOWED_HOSTS=[],此时则ALLOWED_HOSTS默认包括了localhost

而我之前修改了这个配置:ALLOWED_HOSTS=['adminserver'],这时只能够通过adminserver访问,localhost不可以

原因是目前ALLOWED_HOST不为空,所以localhost不会默认添加进去,于是我添加了一项localhost进去,才可以正常访问,即ALLOWED_HOSTS = ['adminserver', 'localhost']

也可改为ALLOWED_HOSTS = ['*'],允许任意host访问

相关推荐
草莓熊Lotso1 分钟前
Python 进阶核心:字典 / 文件操作 + 上下文管理器实战指南
数据结构·c++·人工智能·经验分享·笔记·git·python
天远Date Lab4 分钟前
Python实现用户消费潜力评估:天远个人消费能力等级API对接全攻略
java·大数据·网络·python
一瓢西湖水7 小时前
列式数据库-以clickHouse为例
数据库·clickhouse
Elastic 中国社区官方博客7 小时前
使用 Elastic Cloud Serverless 扩展批量索引
大数据·运维·数据库·elasticsearch·搜索引擎·云原生·serverless
liulanba7 小时前
AI Agent技术完整指南 第一部分:基础理论
数据库·人工智能·oracle
逆天小北鼻8 小时前
Oracle 服务端与客户端的核心区分要点
数据库·oracle
2501_946242938 小时前
MPV-EASY Player (MPV播放器) v0.41.0.1
数据库·经验分享·云计算·计算机外设·github·电脑·csdn开发云
秃了也弱了。8 小时前
python实现定时任务:schedule库、APScheduler库
开发语言·python
Dfreedom.8 小时前
从 model(x) 到__call__:解密深度学习框架的设计基石
人工智能·pytorch·python·深度学习·call
weixin_425023008 小时前
Spring Boot 配置文件优先级详解
spring boot·后端·python