在django上禁止管理电子邮件ALLOWED_HOSTS异常 [英] Suppress admin email on django ALLOWED_HOSTS exception

查看:124
本文介绍了在django上禁止管理电子邮件ALLOWED_HOSTS异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从在django 1.4.4中引入ALLOWED_HOSTS设置以来,我收到了很多django错误的电子邮件给我的管理员地址,由于一些愚蠢的蜘蛛寻找易受攻击的phpMyAdmin安装或somesuch引起的异常。这些邮件是完全有效的,因为蜘蛛请求中的主机头确实是错误的,但是当重要的事情出错时,我宁愿django只会发送错误邮件。有没有一个简单的方法来沉默 SuspiciousOperation 邮件,或者我必须一路走去,并且子类 CommonMiddleware

Since the introduction of the ALLOWED_HOSTS setting in django 1.4.4, I get a lot of django error emails to my admin address for exceptions caused by some silly spider looking for vulnerable phpMyAdmin installations or somesuch. These mails are totally valid since the host headers in the spiders' requests are indeed wrong, but I'd rather have django only send me error mails when important things go wrong. Is there a simple method to silence SuspiciousOperation mails, or do I have to go all the way and subclass CommonMiddleware?

推荐答案

为了完整,您可以覆盖日志记录的部分:(在django 1.6上测试):

For completeness you can override parts of the logging: (tested on django 1.6):

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'null': {
            'level': 'DEBUG',
            'class': 'logging.NullHandler',
        },
    },
    'loggers': {
        'django.security.DisallowedHost': {
            'handlers': ['null'],
            'propagate': False,
        },
    },
}

另请参阅 Django安全文档

这篇关于在django上禁止管理电子邮件ALLOWED_HOSTS异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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