Django 遇到 Invalid HTTP_HOST header

部署Django时,使用

python manage.py runserver 0.0.0.0:8080 

0.0.0.0捆绑监听服务器上的所有网卡IP地址

此时访问遇到

报错:

Invalid HTTP_HOST header: '192.168.2.157:8080'. You may need to add '192.168.2.157' to ALLOWED_HOSTS.
Bad Request: /blog
[31/Dec/2019 08:49:30] "GET /blog HTTP/1.1" 400 58424
Invalid HTTP_HOST header: '192.168.2.157:8080'. You may need to add '192.168.2.157' to ALLOWED_HOSTS.
Bad Request: /favicon.ico
[31/Dec/2019 08:49:31] "GET /favicon.ico HTTP/1.1" 400 58433

解决方法:

  修改settings.py

ALLOWED_HOSTS = ['192.168.2.157','127.0.0.1']

  值为'*',可以使所有的网址都能访问Django项目了,失去了保护的作用,可以用于测试

ALLOWED_HOSTS = ['*']

 

posted @ 2019-12-31 09:01  慕尘  阅读(5984)  评论(0编辑  收藏  举报