Login

Tag "GET"

Snippet List

Querystring Builder - create urls with GET params

Save the code as app_name/templatetags/urlbuilder.py. Supply your view with a dictionary of "default" query params, likely taken from the request. Then, in the template: `{% load urlbuilder %} {% url some-url as base_url %}` That sets you up. Then you can make links. For example: <th><a href="{% build_url base_url query_params sort=name %}">Name</a></th> Say query_params has: page: 2, filter: active, sort: id The above tag would spit out /base/url?page=2&filter=active&sort=name The tag also has support for using a variable as the replacement key. Say "filter_key" is a variable available to the template with the value "filter": {% build_url base_url query_params filter_key default %} Using the above example, that would output /base/url?page=2&filter=default&sort=id

  • tag
  • templatetag
  • url
  • parameter
  • querystring
  • GET
  • param
Read More

Add GET parameter tag

This is custom tag I wrote for myself for solving situations when you have filter form and page numbers in the same page. You want to change ?page=.. or add it if it doesn't exist to save filter form data while moving through pages. Usage: place this code in your application_dir/templatetags/add_url_parameter.py In template: {% load add_get_parameter %} <a href="{% add_get_paramater param1='const_value',param2=variable_in_context %}"> Link with modified params </a> It's required that you have 'django.core.context_processors.request' in TEMPLATE_CONTEXT_PROCESSORS URL: [http://django.mar.lt/2010/07/add-get-parameter-tag.html](http://django.mar.lt/2010/07/add-get-parameter-tag.html)

  • tag
  • parameters
  • GET
  • add
  • add_get_parameter
Read More

2 snippets posted so far.