test environment:
[root@nanx-lli ~]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.4.1708 (Core)
Release: 7.4.1708
Codename: Core
[root@nanx-lli ~]# python
Python 2.7.5 (default, Aug 4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "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.pyc
0 directories, 10 files
[root@nanx-lli HelloWorld]# cat view.py
from django.http import HttpResponse
def hello(request):
return HttpResponse("Hello world!")
question:
PC: Access through chrome on 10.245.36.203, http://10.245.242.221:8000 reports an error, and there is an error log displayed on Linux at the same time:
Invalid HTTP_HOST header: '10.245.242.221:8000'. You may need to add u'10.245.242.221' to ALLOWED_HOSTS.
solution:
Add 10.245.242.221 to allowed_hosts.
Modify setting.py
......
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['10.245.242.221']
# Application definition
......