我有观点:
@decorator
def func(request):
hello = "hello"
return render_to_responce("test.html", locals() )
和模板 test.html:
{{ hello }}
{{ username }}
我想为 编写装饰器func(request)
,它将一个变量 USERNAME 添加到函数中,并在模板中返回两个参数。我试图使它如下:
def decorator(func):
def wrapper( request, *args, **kwargs):
username = request.user.username
q = func(request, *args, **kwargs)
#what I need add here I do not know ...
return q
return wrapper