鉴于以下情况:
from django.shortcuts import render
def decorator(view):
def wrapper(request, *args, **kwargs):
context = {'foo': 'bar'}
# Logic ...
return view(request, *args, **kwargs)
return wrapper
@decorator
def index(request):
return render(request, 'index.html')
我想让装饰器在视图中添加一个上下文字典,以便返回的装饰函数如下所示:
return render(request, 'index.html', context)
这可能吗?