运行django项目出现Invalid HTTP_HOST header:

Linux知识
0 439

csroad
csroad 举报
2019-07-14
运行django项目出现Invalid HTTP_HOST header: '192.168.1.111:8000'. You may need to add '192.168.1.111' to ALLOWED_HOSTSDisallowedHost at /
Invalid HTTP_HOST header: '10.211.55.4:8001'. You may need to add u'10.211.55.4' to ALLOWED_HOSTS.
Request Method:GET
Request URL:http://10.211.55.4:8001/
Django Version:1.11.22
Exception Type:DisallowedHost
Exception Value:
Invalid HTTP_HOST header: '10.211.55.4:8001'. You may need to add u'10.211.55.4' to ALLOWED_HOSTS.
Exception Location:/usr/lib/python2.7/site-packages/django/http/request.py in get_host, line 113
Python Executable:/usr/bin/python
Python Version:2.7.5
Python Path:
['/usr/local/Django/HelloWorld',
 '/usr/lib64/python27.zip',
 '/usr/lib64/python2.7',
 '/usr/lib64/python2.7/plat-linux2',
 '/usr/lib64/python2.7/lib-tk',
 '/usr/lib64/python2.7/lib-old',
 '/usr/lib64/python2.7/lib-dynload',
 '/usr/lib64/python2.7/site-packages',
 '/usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg',
 '/usr/lib/python2.7/site-packages']
Server time:Sun, 14 Jul 2019 08:04:55 +0000
Traceback Switch to copy-and-paste view
  • /usr/lib/python2.7/site-packages/django/core/handlers/exception.py in inner



运行项目时,输入命令#Python manage.py runserver 192.168.1.111:8000,在本机的浏览器中输入http://192.168.1.111:8000

在我们创建的项目里修改setting.py文件

ALLOWED_HOSTS = ['*']  #在这里请求的host添加了*