0

我知道 django 1.4 具有删除错误报告中的敏感信息的功能。我正在使用 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。我尝试过但没有成功。请帮忙。

4

1 回答 1

0

我只是将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 一起提供(我猜) - 你可能必须单独包含该文件。

于 2012-09-06T14:15:12.157 回答