Django中的默认请求上下文
我有一个这样的函数(视图)
def index(request):
return render_to_response('index.html', context_instance=RequestContext(request))
我想要简单地写成
return render_to_response('index.html')
另外,我还想把一些额外的变量传递给视图
return render_to_response('cart.html', {'key': value})
我需要RequestContext的主要原因是我有一个上下文处理函数,它会为我设置一些额外的变量。我该怎么做,或者有没有其他方法可以实现这个功能?
1 个回答
0
你可以使用 render
这个快捷方式:
return render(request, 'cart.html', {'key': value})
不过,你总是需要传递请求信息,这就是为什么它叫做请求上下文(RequestContext)。