我有以下装饰器:
def my_decorator(setting_value):
def actual_decorator(func):
func.my_setting = setting_value
return func
return actual_decorator
我正在尝试my_setting
在这样的上下文处理器中阅读:
# Resolve the url
try:
page_resolve = resolve(request.path_info)
except Resolver404:
return {}
# Get the page view function
page_view = page_resolve.func
if (page_view.my_setting):
return extra_context_data
else
return {}
当使用 CBV 时,整个方案就崩溃了。如何使装饰器与 FBV 和 CBV 兼容?