Skip to content

Instantly share code, notes, and snippets.

@feifangit
Last active December 19, 2015 14:19
Show Gist options
  • Save feifangit/5968520 to your computer and use it in GitHub Desktop.
Save feifangit/5968520 to your computer and use it in GitHub Desktop.
skip exception because of ALLOWED_HOSTS setting
### 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