Reputation: 5371
I'm putting
...}, context_instance=RequestContext(request))
at the end of all my render_to_response
's. I'm sure this is not right. Can anyone tell me when I should be using these?
Upvotes: 1
Views: 2242
Reputation: 18972
If you are using Django 1.3 you can use the render() shortcut function so you don't have to explicitly write context_instance=RequestContext(request)
for each view .
Combines a given template with a given context dictionary and returns an HttpResponse object with that rendered text.
render() is the same as a call to render_to_response() with a context_instance argument that forces the use of a RequestContext.
Upvotes: 5
Reputation: 35619
You are doing it "right". This means that all of the Context Processors will run on this view, and you will have access to all of the juicy bits in your template.
The other way to do this is to use direct_to_template
, which saves you having to instantiate a RequestContext object, but has the same outcomes.
Upvotes: 3