首页 > 解决方案 > 试图让 log_error 装饰器在 Django 中工作,但得到元组错误

问题描述

试图模仿这篇文章中的第一个答案并创建一个 log_error 装饰器: 将所有错误记录到控制台或 Django 站点上的文件

这是我得到的错误:

raise TypeError('view must be a callable or a list/tuple in the case of include().')
TypeError: view must be a callable or a list/tuple in the case of include().

也许我不应该把这个函数放在views.py中,或者这在Django 2.2.3中不起作用?

def log_error(func):
 def _call_func(*args, **argd):
    try:
        func(*args, **argd)
    except:
        print("error") #substitute your own error handling
    return _call_func

标签: djangologgingdecoratorerror-logging

解决方案


推荐阅读