Login

Tag "querystring"

Snippet List

get_querystring template tag

A Django Template tag used to construct urls with current querystring parameters. This is based on some code that I've written some years ago. Enjoy.

  • template
  • templatetag
  • querystring
Read More

Add querystring parameters to path (template tag)

`<h3>Page: {{ page.number }} of {{ page.paginator.num_pages }}</h3> {% if page.has_previous or page.has_next %} <div> {% if page.has_previous %} <a href="{% url_add_query page=page.previous_page_number %}">{% endif %}&laquo; Previous {% if page.has_previous %}</a>{% endif %} | {% if page.has_next %} <a href="{% url_add_query page=page.next_page_number %}">{% endif %} Next &raquo;{% if page.has_next %}</a>{% endif %} </div> {% endif %}`

  • template
  • templatetag
  • pagination
  • request
  • querystring
  • query-string
Read More

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

Sessions and authentication without cookies

[The Session documentation](http://www.djangoproject.com/documentation/sessions/) rightly warns of the dangers of putting a session ID into a query string. Sometimes, however, you have to do it - perhaps your client has mandated support for browsers with cookies disabled, or perhaps (as in my case) you're just dealing with a slightly broken client browser. This middleware pulls a session ID out of the query string an inserts it into the cookies collection. You'll need to include it in your MIDDLEWARE_CLASSES tuple in settings.py, *before* the SessionMiddleware. *Please* read my [full blog post](http://www.stereoplex.com/two-voices/cookieless-django-sessions-and-authentication-without-cookies) about for the dangers of doing this, and for full instructions and examples.

  • middleware
  • cookie
  • session
  • authentication
  • string
  • query
  • cookieless
  • querystring
Read More

4 snippets posted so far.