0

我有这样的功能(查看)

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 的主要原因是我有上下文处理器功能,可以为我设置额外的变量。我怎样才能做到这一点,或者有不同的方法来做这样的事情?

4

1 回答 1

0

您可以使用render快捷方式:

return render(request, 'cart.html', {'key': value})

但是,您总是需要传递请求:这就是它被称为 RequestContext 的原因。

于 2014-10-30T14:20:59.147 回答