我想编写一个decorator,它将为模板呈现上下文提供值,如下所示:
@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))
我最初的尝试是这样的:
^{pr2}$但是,这不起作用,因为请求不是真正的dict
我如何实现这一点?在
唯一的方法是如果decorator本身负责呈现和返回模板。有一个相当成熟的代码片段正是这样做的:render_to装饰器。其思想是视图只返回一个字典,而decorator实际呈现它。您应该能够编辑该片段,以便它处理默认情况。在
相关问题 更多 >
编程相关推荐