测试环境:
[root@nanx-lli ~]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarchDistributor ID: CentOSDescription: CentOS Linux release 7.4.1708 (Core)Release: 7.4.1708Codename: Core [root@nanx-lli ~]# pythonPython 2.7.5 (default, Aug 4 2017, 00:39:18)[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import django>>> django.VERSION(1, 11, 12, u'final', 0)
[root@nanx-lli HelloWorld]# pwd
/root/HelloWorld/HelloWorld[root@nanx-lli HelloWorld]# tree.├── __init__.py├── __init__.pyc├── settings.py├── settings.pyc├── urls.py├── urls.pyc├── view.py├── view.pyc├── wsgi.py└── wsgi.pyc0 directories, 10 files
[root@nanx-lli HelloWorld]# cat view.pyfrom django.http import HttpResponse
def hello(request):
return HttpResponse("Hello world!")
问题:
PC: 10.245.36.203上通过chrome访问,http://10.245.242.221:8000时报错,并且此时在Linux上同时有错误log显示:
Invalid HTTP_HOST header: '10.245.242.221:8000'. You may need to add u'10.245.242.221' to ALLOWED_HOSTS.
解决方案:
添加10.245.242.221到allowed_hosts.
修改setting.py
......
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = TrueALLOWED_HOSTS = ['10.245.242.221']
# Application definition
......