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

#python manage.py runserver 8888
CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.

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

提示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. 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.

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).
Changed in Django 1.7: 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:
ALLOWED_HOSTS = [
'.example.com', # Allow domain and subdomains
'.example.com.', # Also allow FQDN and subdomains
]


In Django 1.7, the trailing dot is stripped when performing host validation, thus an entry with a trailing dot isn’t required.

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.

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.

This validation only applies via get_host(); if your code accesses the Host header directly from request.META you are bypassing this security protection.

django DEBUG=False的更多相关文章

  1. Python django 404页面配置和debug=false 静态文件配置 django版本1.10.5

    django设置404页面 1.设置settings文件 DEBUG = False ALLOWED_HOSTS = ['127.0.0.1', 'localhost']或者 ALLOWED_HOST ...

  2. 配置Django框架为生产环境的注意事项(DEBUG=False)

    问题描述: Django1.10版本中框架中settings.py配置文件 配置文件settings.py配置了下面两项: DEBUG= False ALLOWED_HOSTS = ['*'] #这样 ...

  3. Django设置 DEBUG=False后静态文件无法加载

    修改setting.py STATIC_URL = '/static/' STATIC_ROOT = 'static' ## 新增行 STATICFILES_DIRS = [ os.path.join ...

  4. Django设置 DEBUG=False后静态文件无法加载解决

    前段时间调试一直是在Debug=True先运行的,没有什么问题.今天关闭了Debug后,出现了一个问题.就是静态文件找不到了,「img.css.js」都提示404,无法准确的访问 static 静态文 ...

  5. Django settings.py设置 DEBUG=False后静态文件无法加载解决

    解决办法: settings.py 文件 DEBUG = False STATIC_ROOT = os.path.join(BASE_DIR,'static') #新增 urls.py文件(项目的) ...

  6. django 注册后台管理 在debug=true能行,在debug=false不能显示出管理标签

    debug=true 下,如下图:

  7. 部署前准备--使用Mysql之Django Debug Toolbar安装以及配置

    python -c "import django ;print(django.__path__);" 查看python的全局配置 vi /usr/local/lib/python3 ...

  8. Django之Django debug toolbar调试工具

    一.安装Django debug toolbar调试工具 pip3 install django-debug-toolbar 如果出错命令为 pip install django_debug_tool ...

  9. 【Django】Django Debug Toolbar调试工具配置

    正在发愁怎么调试Django,就遇到了Django Debug Toolbar这个利器. 先说遇到的问题: 网上也有教程,不过五花八门的,挨个尝试了一遍,也没有成功运行.最后终于找到问题所在: 从开发 ...

随机推荐

  1. VMwear安装Centos7超详细过程

    本篇文章主要介绍了VMware安装Centos7超详细过程(图文),具有一定的参考价值,感兴趣的小伙伴们可以参考一下 1.软硬件准备 软件:推荐使用VMwear,我用的是VMwear 12 镜像:Ce ...

  2. cgi调用linux系统命令

    1.例如:建一个目录:system("mkdir yourdir").(1)首先:要用root用户如果cgi中要用root用户,则必须在boa.conf文件中配置,将User no ...

  3. WEB常用前端开发调试工具介绍

    只要是设计开发,就需要进行调试,尽管相对来说,前端的调试要简单一些,但使用一些调试工具或插件还是能提高你的工作效率.下面是一些主要用于IE浏览器环境和Firefox浏览器环境等的调试工具简介. 一.I ...

  4. windows的cmd下面格式化某个盘符

    1.crl+R 输入cmd回车. 2.如果要格式化的是E盘,哪直接输入 在DOS窗口中输入“format  f: “ ,其中:format 为格式化命令,f: 为需要格式化的分区

  5. VBox添加虚拟磁盘挂载

    1. 关闭虚拟机,然后在设置里面选择添加虚拟硬盘 2.lsblk检查存在10G sdb虚拟磁盘 fdisk -l 检查 /dev/sdb 尚没有分区 3.磁盘分区 4.检查分区状况lsblk 5.格式 ...

  6. JIT物料在途未清PO作为供给

    以下是本应在TEMP中处理,目前是写到FP_CHECK_SAP_DATA中 ----JIT物料在途未清PO作为供给 add by landor on 20180809 INSERT INTO SAP_ ...

  7. 四、API使用参考

    官方文档:https://docs.blender.org/api/blender_python_api_current/info_api_reference.html Blender有很多互连数据类 ...

  8. nutch笔记

    1.Nutch 是一个开源Java实现的搜索引擎.它提供了我们运行自己的搜索引擎所需的全部工具.包括全文搜索和Web爬虫.

  9. 第九章 词典 (c)散列:散列函数

  10. tight

    tight - 必应词典 美[taɪt]英[taɪt] adv.紧紧地:牢固地 adj.牢固的:紧的:不松动的:难解开的 n.紧身衣 网络紧身的:紧密的:密封的 变形比较级:tighter:最高级:t ...