How to print url ‘GET’ variables in Django template

There are two ways to achieve this:

1. By sending the request object as part of the context dictionary that will be read by the template, like this:

def yourView(request):
c = {}
c["request"] = request
return render_to_response("yourtemplate.html", c, context_instance=RequestContext(request))

2. By activating the django.core.context_processors.request template context processor, which will automatically send the request variable for you to the template, instead of making you send it manually:


Both methods will allow you to print a GET variable. For example, if your url is http://localhost:8000/?foo=1234 , then you can print the variable foo in your template like this:

{{ }}


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: