# Template tags

## render_table

Renders a `Table` object to HTML and enables as many features in the output as possible.

    {% load django_tables2 %}
    {% render_table table %}

    {# Alternatively a specific template can be used #}
    {% render_table table "path/to/custom_table_template.html" %}

If the second argument (template path) is given, the template will be rendered with a `RequestContext` and the table will be in the variable `table`.

Note

This tag temporarily modifies the `Table` object during rendering. A `context` attribute is added to the table, providing columns with access to the current context for their own rendering (e.g. `TemplateColumn`).

This tag requires that the template in which it’s rendered contains the `HttpRequest` inside a `request` variable. This can be achieved by ensuring the `TEMPLATES[]['OPTIONS']['context_processors']` setting contains `django.template.context_processors.request`. Please refer to the Django documentation for the TEMPLATES-setting.

## querystring_replace

Note

This tag has been renamed from `querystring` to avoid shadowing the `Django template tag` with the same name.

A utility that allows you to update a portion of the query-string without overwriting the entire thing.

Let’s assume we have the query string `?search=pirates&sort=name&page=5` and we want to update the `sort` parameter:

    {% querystring_replace "sort"="dob" %}           # ?search=pirates&sort=dob&page=5
    {% querystring_replace "sort"="" %}              # ?search=pirates&page=5
    {% querystring_replace "sort"="" "search"="" %}  # ?page=5

    {% with "search" as key %}                       # supports variables as keys
    {% querystring_replace key="robots" %}           # ?search=robots&page=5
    {% endwith %}

This tag requires the `django.template.context_processors.request` context processor, see render_table.