Django newbie here, I’m using
render_to_response('example.html', {
'error_message': error_message,
}, context_instance=RequestContext(request))
How do I use the request in the template? (e.g. the request.host etc.)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The whole point of the context processors is that they automatically add the elements to the context. So you can just use
{{ request.host }}or whatever directly in the template.Edit after comment No, this has nothing to do with generic views. Generic views act in exactly the same way as your own views that use RequestContext as you show above. If you want to make the
requestobject available automatically in your views all you need to do is to add the code below to your settings.py – hard to see how this could be any quicker.(This is just the default list of context processors as described in the docs, with the
requestone added.)