djangoDEBUG=False

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

在django的settings中. 将DEBUG 设置为False. 会出现

#python manage.py runserver 8888

CommandError: You must set settings.ALLOWED_HOSTSifDEBUGisFalse.

#####################################################

提示DEBUG为False时,必须设置settings.ALLOWED_HOSTS .

ALLOWED_HOSTS =['.example.com',#Allow domain and subdomains'.example.com.',#Also allow FQDN and subdomains]

或者您需要设置所有的均可访问.那么可以这样设置.

ALLOWED_HOSTS = ['*']

任何用户均可以访问.

然后再访问下.恢复正常.

相关django官方文档.

https://docs.djangoPRoject.com/en/1.7/ref/settings/

在此引用一下.

ALLOWED_HOSTS¶

Default: [] (Empty list)

A list of strings representing the host/domain names that this Django site can serve. Thisisa security measure to prevent an attackerfrompoisoning cachesandpassWordreset emails with links to malicious hosts by submitting requests with a fake HTTP Host header, whichispossible even under many seemingly-safe web server configurations.

Valuesinthis list can be fully qualified names (e.g.'www.example.com'),inwhich case they will be matched against the request’s Host header exactly (case-insensitive,notincluding port). A value beginning with a period can be used as a subdomain wildcard:'.example.com'will match example.com, www.example.com,andany other subdomain of example.com. A value of'*'will match anything;inthis case you are responsible to provide your own validation of the Host header (perhapsina middleware;ifso this middleware must be listed firstinMIDDLEWARE_CLASSES).

ChangedinDjango 1.7:

In previous versions of Django,ifyou wanted to also allow the fully qualified domain name (FQDN), which some browsers can sendinthe Host header, you had to explicitly add another ALLOWED_HOSTS entry that included a trailing period. This entry could also be a subdomain wildcard:

ALLOWED_HOSTS =['.example.com',#Allow domain and subdomains'.example.com.',#Also allow FQDN and subdomains]

In Django1.7, the trailing dotisstripped when performing host validation, thus an entry with a trailing dot isn’t required.

If the Host header (orX-Forwarded-HostifUSE_X_FORWARDED_HOSTisenabled) doesnotmatch any valueinthis list, the django.http.HttpRequest.get_host() method willraiseSuspiciousOperation.

When DEBUGisTrueorwhen running tests, host validationisdisabled; any host will be accepted. Thus it’s usually only necessary to set itinproduction.

This validation only applies via get_host();ifyour codeaccesses the Host header directlyfromrequest.META you are bypassing this security protection.

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航