Django ALLOWED_HOSTS等同于被禁止的主机? [英] Django ALLOWED_HOSTS equivalent for banned host?

查看:2495
本文介绍了Django ALLOWED_HOSTS等同于被禁止的主机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Django 1.5中,您可以设置允许的主机:

In Django 1.5 you can set allowed hosts:

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

是否有相当于被禁止的主机?即我提供的IP列表只是自动拒绝?

Is there an equivalent for banned hosts? i.e. I provide a list of IP's to just automatically reject?

推荐答案

根据文档说明,您可以通过中间件:

You can pass through a middleware, as the documentation says:

值*将匹配任何东西;在这种情况下,您有责任提供您自己对Host头的验证(也许在一个中间件中);如果是这样,这个中间件必须首先列在MIDDLEWARE_CLASSES中。

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).

请参阅 Django设置文档

这篇关于Django ALLOWED_HOSTS等同于被禁止的主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆