Django 遇到 Invalid HTTP_HOST header

部署Django時,使用python

python manage.py runserver 0.0.0.0:8080

0.0.0.0捆綁監聽服務器上的全部網卡IP地址服務器

此時訪問遇到測試

報錯:spa

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 58433code

解決方法:server

  修改settings.pyblog

ALLOWED_HOSTS = ['192.168.2.157','127.0.0.1']

  值爲'*',可使全部的網址都能訪問Django項目了,失去了保護的做用,能夠用於測試部署

ALLOWED_HOSTS = ['*']
相關文章
相關標籤/搜索