Last active
December 19, 2015 14:19
-
-
Save feifangit/5968520 to your computer and use it in GitHub Desktop.
skip exception because of ALLOWED_HOSTS setting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### in a seperated file define the function | |
from django.core.exceptions import SuspiciousOperation | |
def skip_suspicious_exception(record): | |
if record.exc_info: | |
exc_type, exc_value = record.exc_info[:2] | |
if isinstance(exc_value, SuspiciousOperation): | |
return False | |
return True | |
### in settings.py ### | |
LOGGING = { | |
'version': 1, | |
'disable_existing_loggers': False, | |
'filters': { | |
'require_debug_false': { | |
'()': 'django.utils.log.RequireDebugFalse' | |
}, | |
'skip_host_check': { | |
'()': 'django.utils.log.CallbackFilter', | |
'callback': skip_suspicious_exception, | |
} | |
}, | |
'handlers': { | |
'mail_admins': { | |
'level': 'ERROR', | |
'filters': ['require_debug_false', 'skip_host_check'], | |
'class': 'django.utils.log.AdminEmailHandler' | |
} | |
}, | |
'loggers': { | |
'django.request': { | |
'handlers': ['mail_admins'], | |
'level': 'ERROR', | |
'propagate': True, | |
}, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment