1
어떻게하면 장고 뷰 데코레이터에서 컨텍스트의 값을 설정할 수 있습니까?
템플릿 렌더링 컨텍스트에 값을 제공 할 데코레이터를 작성하려고합니다.@deco(art=Nouveau)
def my_wall(request):
# should have art == 'something' in the template
return render_from_template('plain_white.html', {art:'something'}, context_instance=RequestContext(request))
@deco(art=Nouveau)
def my_wall(request):
# should have art == Nouveau in the template
return render_from_template('plain_white.html', {}, context_instance=RequestContext(request))
이를 구현하기위한 초기 시도는 다음과 같습니다 :
class deco(object):
def __init__(self, art=None):
self.art = art
def __call__(self, f):
@wraps(f)
def wrapper(request, *args, **kwargs):
if self.art:
request.setdefault('art', self.art)
return f(request, *args, **kwargs)
요청이 실제 사전이 아니기 때문에 작동하지 않습니다.
어떻게 구현할 수 있습니까?