Login

Tag "parameter"

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 multiple parameters to the current url

Add multiple parameters to the current url.<br /> **Usage:**<br /> `{% addparam name1 value1 name2 value2 %}`<br /> or<br /> `{% addparam "name1" value1 "name2" value2 %}`<br /> variable can be use inplace of names and values<br /> example: <br />`{% addparam "view" message.id %}`

  • url
  • templatetags
  • parameter
Read More

Add parameters to the current url

Often a page contains a link to itself, with an additional parameter for in the url. E.g. to sort the page in a different way, to export the data into another format, etc... This tag makes this easy, avoiding any hardcoded urls in your pages.

  • url
  • parameter
Read More

3 snippets posted so far.