Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output request parameter by template

Is it correct to say that there is no simple tag that just writes some http get query parameter? If all needed is printing a http get query parameter e.g. ?q=w can I directly use the value q with a template tag or need the copy the value in the request handler? Is it possible to more directly pass values (all values) from http get to template? Because copying every value seems repeating the same handling many times

template_values = {'q':self.request.get('q'),... 

It should be possible to iterate the parameter set. Can you recommend that or any other solution?

like image 499
Niklas Rosencrantz Avatar asked Oct 25 '10 08:10

Niklas Rosencrantz


1 Answers

You don't need to do this at all. The request is available in the template context automatically (as long as you enable the request context processor and use a RequestContext) - or you can just pass the request object directly in the context.

And request.GET is a dictionary-like object, so once you have the request you can get the GET values directly in the template:

{{ request.GET.q }} 
like image 187
Daniel Roseman Avatar answered Sep 28 '22 05:09

Daniel Roseman