Django 1.3错误报告删除敏感信息 [英] Django 1.3 Error report remove sensitive information

查看:128
本文介绍了Django 1.3错误报告删除敏感信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道django 1.4具有删除敏感信息的错误报告的功能。我正在使用django 1.3和python 2.4.我想知道是否 https://docs.djangoproject.com/en/dev/howto/error-reporting/#filtering-error-report 回到可移植到django 1.3和python 2.4.我尝试没有成功。请帮助。

I know django 1.4 has functionality to remove Sensible information in error report.I am using django 1.3 and python 2.4.I want to know whether https://docs.djangoproject.com/en/dev/howto/error-reporting/#filtering-error-reports is back portable to django 1.3 and python 2.4.I tried with no success.please help.

推荐答案

我只是复制敏感信息装饰器到本地的decorators.py文件,并使用它。

I would just copy the sensitive_information decorator to a local decorators.py file, and use it.

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,wh我不会默认使用python2.4(我猜) - 你可能需要分开包含该文件。

Would need functools.py too, which would not come with python2.4 by default (I guess) -you might have to include that file separately.

这篇关于Django 1.3错误报告删除敏感信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆