Django 遇到 Invalid HTTP_HOST header

When deploying Django, use

python manage.py runserver 0.0.0.0:8080 

All IP addresses on the network adapter bundled monitor server 0.0.0.0

At this visit met

Error:

Invalid HTTP_HOST header: '192.168.2.157:8080'. You may need to add '192.168.2.157' to ALLOWED_HOSTS.
Bad Request: /blog
[31/Dec/2019 08:49:30] "GET /blog HTTP/1.1" 400 58424
Invalid HTTP_HOST header: '192.168.2.157:8080'. You may need to add '192.168.2.157' to ALLOWED_HOSTS.
Bad Request: /favicon.ico
[31/Dec/2019 08:49:31] "GET /favicon.ico HTTP/1.1" 400 58433

Solution:

  Modify settings.py

ALLOWED_HOSTS = ['192.168.2.157','127.0.0.1']

  Is '*', can make all the URLs can access the Django project, and lost the role of protection, it can be used to test

Guess you like

Origin www.cnblogs.com/baby123/p/12122703.html