Django 1.3错误报告删除敏感信息
问题描述:
我知道django 1.4具有删除错误报告中的Sensible信息的功能。我使用的是django 1.3和python 2.4。我想知道https://docs.djangoproject.com/en/dev/howto/error-reporting/#filtering-error-report s是否可以移植到django 1.3和python 2.4。我试过没有成功,请帮忙。Django 1.3错误报告删除敏感信息
答
我只需将sensitive_information修饰符复制到本地decorators.py文件中,然后使用它。
import functools
def sensitive_variables(*variables):
"""
Indicates which variables used in the decorated function are sensitive, so
that those variables can later be treated in a special way, for example
by hiding them when logging unhandled exceptions.
Two forms are accepted:
* with specified variable names:
@sensitive_variables('user', 'password', 'credit_card')
def my_function(user):
password = user.pass_word
credit_card = user.credit_card_number
...
* without any specified variable names, in which case it is assumed that
all variables are considered sensitive:
@sensitive_variables()
def my_function()
...
"""
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
if variables:
wrapper.sensitive_variables = variables
else:
wrapper.sensitive_variables = '__ALL__'
return func(*args, **kwargs)
return wrapper
return decorator
用法:
@sensitive_variables('user', 'pw', 'cc')
def my_view(request):
pass
那就需要functools.py太多,这将不附带默认的python2.4(我猜) - 您可能必须单独包括文件。
我以前曾经试过你说过的。问题是python 2.4不支持functools。 – shiva