使用Django出现的问题及解决办法
===========================================================================================
【问题一】安装好Django,并且创建好了一个项目,然后浏览器中打开时出现以下问题
DisallowedHost at /
Invalid HTTP_HOST header: ‘172.16..:8000‘. You may need to add u‘172.16.40.247‘ to ALLOWED_HOSTS.
Request Method: | GET |
---|---|
Request URL: | http://172.16..:8000/ |
Django Version: | 1.11.5 |
Exception Type: | DisallowedHost |
Exception Value: |
Invalid HTTP_HOST header: ‘172.16.40.247:8000‘. You may need to add u‘172.16.40.247‘ to ALLOWED_HOSTS. |
Exception Location: | /usr/lib/python2.7/site-packages/Django-1.11.5-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/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/psutil-5.3.1-py2.7-linux-x86_64.egg‘, ‘/usr/lib/python2.7/site-packages‘, ‘/usr/lib/python2.7/site-packages/setuptools-36.4.0-py2.7.egg‘, ‘/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg‘, ‘/usr/lib/python2.7/site-packages/ansible-1.7.2-py2.7.egg‘, ‘/usr/lib/python2.7/site-packages/Django-1.11.5-py2.7.egg‘, ‘/usr/lib/python2.7/site-packages/pytz-2017.2-py2.7.egg‘] |
Server time: | Sat, 16 Sep 2017 04:47:28 +0000 |
【解决办法】
找项目的settings.py文件,将
ALLOWED_HOSTS = [] 修改为
ALLOWED_HOSTS = [‘*‘]
时间: 2024-11-07 19:31:27