Django运行项目时候出现DisallowedHost at / Invalid HTTP_HOST header:
web端错误现象:
DisallowedHost at /
Invalid HTTP_HOST header: 'ip:8000'. You may need to add u'ip' to ALLOWED_HOSTS.
Request Method: | GET |
---|---|
Request URL: | http://ip:8000/ |
Django Version: | 1.10.8 |
Exception Type: | DisallowedHost |
Exception Value: |
Invalid HTTP_HOST header: 'ip:8000'. You may need to add u'ip' to ALLOWED_HOSTS. |
Exception Location: | /usr/lib/python2.7/site-packages/Django-1.10.8-py2.7.egg/django/http/request.py in get_host, line 113 |
Python Executable: | /usr/bin/python |
Python Version: | 2.7.5 |
Python Path: |
['/root/mysite', '/usr/lib/python2.7/site-packages/requests-2.18.4-py2.7.egg', '/usr/lib/python2.7/site-packages/certifi-2017.11.05-py2.7.egg', '/usr/lib/python2.7/site-packages/urllib3-1.22-py2.7.egg', '/usr/lib/python2.7/site-packages/idna-2.6-py2.7.egg', '/usr/lib/python2.7/site-packages/chardet-3.0.4-py2.7.egg', '/usr/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg', '/usr/lib/python2.7/site-packages/Django-1.10.8-py2.7.egg', '/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/lib/python2.7/site-packages'] |
Server time: | Sun, 24 Dec 2017 14:07:20 +0000 |
服务器端错误现象:
解决方法:
修改settings.py这个文件里面的配置文件:
在ALLOWED_HOSTS = ['']里面的中括号里面添加*,如下。
ALLOWED_HOSTS = ['*']
保存退出,刷新web页面即可