指定Django工程的IP和端口后项目运行没有出问题,但是无法访问端口且报错:Invalid HTTP_HOST header: '192.168.0.102:9999'. You may need

cmd中报错内容为:

D:\resp_work\py_1707A\days02\mysite>python manage.py runserver 192.168.0.102:9999
Performing system checks...

System check identified no issues (0 silenced).

You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
May 02, 2020 - 17:49:19
Django version 1.11.6, using settings 'mysite.settings'
Starting development server at http://192.168.0.102:9999/
Quit the server with CTRL-BREAK.
Invalid HTTP_HOST header: '192.168.0.102:9999'. You may need to add '192.168.0.102' to ALLOWED_HOSTS.
[02/May/2020 17:49:29] "GET / HTTP/1.1" 400 62276
Invalid HTTP_HOST header: '192.168.0.102:9999'. You may need to add '192.168.0.102' to ALLOWED_HOSTS.
[02/May/2020 17:49:29] "GET /favicon.ico HTTP/1.1" 400 62200
Invalid HTTP_HOST header: '192.168.0.102:9999'. You may need to add '192.168.0.102' to ALLOWED_HOSTS.
[02/May/2020 17:49:49] "GET / HTTP/1.1" 400 62276
Invalid HTTP_HOST header: '192.168.0.102:9999'. You may need to add '192.168.0.102' to ALLOWED_HOSTS.
[02/May/2020 17:49:50] "GET /favicon.ico HTTP/1.1" 400 62200

报错原因是:我们的Django工程并没有打开192.168.0.102端口,所以需要打开

解决方案是:

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

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

你可能感兴趣的:(Django)