Django错误报告删除敏感信息

2024-05-18 15:33:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道django1.4有删除错误报告中的敏感信息的功能,我使用的是django1.3和python2.4,我想知道https://docs.djangoproject.com/en/dev/howto/error-reporting/#filtering-error-reports是否可以重新移植到django1.3和python2.4上。我尝试过没有成功。请救命啊。在


Tags: httpsdev功能com信息docserroren
1条回答
网友
1楼 · 发布于 2024-05-18 15:33:57

我只要把敏感信息装饰器复制到本地装饰工.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

用法:

^{pr2}$

需要函数工具.py另外,默认情况下python2.4不会附带这个文件(我猜)——您可能需要单独包含该文件。在

相关问题 更多 >

    热门问题