免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1900 | 回复: 0
打印 上一主题 下一主题

django DEBUG=False [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-06-18 10:55 |只看该作者 |倒序浏览
在django的settings中. 将DEBUG 设置为False. 会出现
  1. #python manage.py runserver 8888
复制代码
  1. CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.
复制代码
#####################################################

提示DEBUG为False时,必须设置settings.ALLOWED_HOSTS .
  1. ALLOWED_HOSTS = [
  2.     '.example.com',  # Allow domain and subdomains
  3.     '.example.com.',  # Also allow FQDN and subdomains
  4. ]
复制代码
或者您需要设置所有的均可访问.那么可以这样设置.
  1. ALLOWED_HOSTS = ['*']
复制代码
任何用户均可以访问.
然后再访问下.恢复正常.



相关django官方文档.
https://docs.djangoproject.com/en/1.7/ref/settings/
在此引用一下.
  1. ALLOWED_HOSTS¶

  2. Default: [] (Empty list)

  3. A list of strings representing the host/domain names that this Django site can serve. This is a security measure to prevent an attacker from poisoning caches and password reset emails with links to malicious hosts by submitting requests with a fake HTTP Host header, which is possible even under many seemingly-safe web server configurations.

  4. Values in this list can be fully qualified names (e.g. 'www.example.com'), in which case they will be matched against the request’s Host header exactly (case-insensitive, not including port). A value beginning with a period can be used as a subdomain wildcard: '.example.com' will match example.com, www.example.com, and any other subdomain of example.com. A value of '*' will match anything; in this case you are responsible to provide your own validation of the Host header (perhaps in a middleware; if so this middleware must be listed first in MIDDLEWARE_CLASSES).
  5. Changed in Django 1.7:

  6. In previous versions of Django, if you wanted to also allow the fully qualified domain name (FQDN), which some browsers can send in the Host header, you had to explicitly add another ALLOWED_HOSTS entry that included a trailing period. This entry could also be a subdomain wildcard:
复制代码
  1. ALLOWED_HOSTS = [
  2.     '.example.com',  # Allow domain and subdomains
  3.     '.example.com.',  # Also allow FQDN and subdomains
  4. ]
复制代码
  1. In Django 1.7, the trailing dot is stripped when performing host validation, thus an entry with a trailing dot isn’t required.

  2. If the Host header (or X-Forwarded-Host if USE_X_FORWARDED_HOST is enabled) does not match any value in this list, the django.http.HttpRequest.get_host() method will raise SuspiciousOperation.

  3. When DEBUG is True or when running tests, host validation is disabled; any host will be accepted. Thus it’s usually only necessary to set it in production.

  4. This validation only applies via get_host(); if your code accesses the Host header directly from request.META you are bypassing this security protection.
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP