[英]Default RequestContext in Django
I have such a function(view) 我有这样的功能(查看)
def index(request):
return render_to_response('index.html', context_instance=RequestContext(request))
and want to write just 而且只想写
return render_to_response('index.html')
Also I want to pass additional variables to view 我也想传递其他变量来查看
return render_to_response('cart.html', {'key': value})
The main reason I need RequestContext is that I have context processor function that sets additional variables for me. 我需要RequestContext的主要原因是我具有上下文处理器功能,可以为我设置其他变量。 How can I achieve that or is there different approach for doing such a thing?
我如何实现这一目标,或者有其他方法可以做到这一点?
You can use the render
shortcut: 您可以使用
render
快捷方式:
return render(request, 'cart.html', {'key': value})
You always need to pass the request, though: that's why it's called a RequestContext. 但是,您始终需要传递请求:这就是为什么它被称为RequestContext的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.