<!DOCTYPE html>

<html lang="en" data-content_root="../../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

    <title>Built-in template tags and filters &#8212; Django 5.2.8 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=34bb78ad" />
    <link rel="stylesheet" type="text/css" href="../../_static/default.css?v=bf4d74af" />
    <script src="../../_static/documentation_options.js?v=1e3ff871"></script>
    <script src="../../_static/doctools.js?v=9bcbadda"></script>
    <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="The Django template language: for Python programmers" href="api.html" />
    <link rel="prev" title="The Django template language" href="language.html" />



 
<script src="../../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "#";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../index.html">Django 5.2.8 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../index.html">Home</a>  |
        <a title="Table of contents" href="../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../genindex.html">Index</a>  |
        <a title="Module index" href="../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="language.html" title="The Django template language">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="api.html" title="The Django template language: for Python programmers">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-templates-builtins">
            
  <section id="s-built-in-template-tags-and-filters">
<span id="built-in-template-tags-and-filters"></span><h1>Built-in template tags and filters<a class="headerlink" href="#built-in-template-tags-and-filters" title="Link to this heading">¶</a></h1>
<p>This document describes Django’s built-in template tags and filters. It is
recommended that you use the <a class="reference internal" href="../contrib/admin/admindocs.html"><span class="doc">automatic documentation</span></a>, if available, as this will also include
documentation for any custom tags or filters installed.</p>
<section id="s-built-in-tag-reference">
<span id="s-ref-templates-builtins-tags"></span><span id="built-in-tag-reference"></span><span id="ref-templates-builtins-tags"></span><h2>Built-in tag reference<a class="headerlink" href="#built-in-tag-reference" title="Link to this heading">¶</a></h2>
<section id="s-autoescape">
<span id="s-std-templatetag-autoescape"></span><span id="autoescape"></span><span id="std-templatetag-autoescape"></span><h3><code class="docutils literal notranslate"><span class="pre">autoescape</span></code><a class="headerlink" href="#autoescape" title="Link to this heading">¶</a></h3>
<p>Controls the current auto-escaping behavior. This tag takes either <code class="docutils literal notranslate"><span class="pre">on</span></code> or
<code class="docutils literal notranslate"><span class="pre">off</span></code> as an argument and that determines whether auto-escaping is in effect
inside the block. The block is closed with an <code class="docutils literal notranslate"><span class="pre">endautoescape</span></code> ending tag.</p>
<p>Sample usage:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">autoescape</span> <span class="nv">on</span> <span class="cp">%}</span>
    <span class="cp">{{</span> <span class="nv">body</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">endautoescape</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>When auto-escaping is in effect, all content derived from variables has HTML
escaping applied before placing the result into the output (but after any
filters are applied). This is equivalent to manually applying the
<a class="reference internal" href="#std-templatefilter-escape"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">escape</span></code></a> filter to each variable.</p>
<p>The only exceptions are variables already marked as “safe” from escaping.
Variables could be marked as “safe” by the code which populated the variable,
by applying the <a class="reference internal" href="#std-templatefilter-safe"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">safe</span></code></a> or <a class="reference internal" href="#std-templatefilter-escape"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">escape</span></code></a> filters, or because it’s
the result of a previous filter that marked the string as “safe”.</p>
<p>Within the scope of disabled auto-escaping, chaining filters, including
<a class="reference internal" href="#std-templatefilter-escape"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">escape</span></code></a>, may cause unexpected (but documented) results such as the
following:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">autoescape</span> <span class="nv">off</span> <span class="cp">%}</span>
    <span class="cp">{{</span> <span class="nv">my_list</span><span class="o">|</span><span class="nf">join</span><span class="s2">:&quot;, &quot;</span><span class="o">|</span><span class="nf">escape</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">endautoescape</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>The above code will output the joined elements of <code class="docutils literal notranslate"><span class="pre">my_list</span></code> unescaped. This
is because the filter chaining sequence executes first <a class="reference internal" href="#std-templatefilter-join"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">join</span></code></a> on
<code class="docutils literal notranslate"><span class="pre">my_list</span></code> (without applying escaping to each item since <code class="docutils literal notranslate"><span class="pre">autoescape</span></code> is
<code class="docutils literal notranslate"><span class="pre">off</span></code>), marking the result as safe. Subsequently, this safe result will be
fed to <a class="reference internal" href="#std-templatefilter-escape"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">escape</span></code></a> filter, which does not apply a second round of
escaping.</p>
<p>In order to properly escape every element in a sequence, use the
<a class="reference internal" href="#std-templatefilter-escapeseq"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">escapeseq</span></code></a> filter:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">autoescape</span> <span class="nv">off</span> <span class="cp">%}</span>
    <span class="cp">{{</span> <span class="nv">my_list</span><span class="o">|</span><span class="nf">escapeseq</span><span class="o">|</span><span class="nf">join</span><span class="s2">:&quot;, &quot;</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">endautoescape</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-block">
<span id="s-std-templatetag-block"></span><span id="block"></span><span id="std-templatetag-block"></span><h3><code class="docutils literal notranslate"><span class="pre">block</span></code><a class="headerlink" href="#block" title="Link to this heading">¶</a></h3>
<p>Defines a block that can be overridden by child templates. See
<a class="reference internal" href="language.html#template-inheritance"><span class="std std-ref">Template inheritance</span></a> for more information.</p>
</section>
<section id="s-comment">
<span id="s-std-templatetag-comment"></span><span id="comment"></span><span id="std-templatetag-comment"></span><h3><code class="docutils literal notranslate"><span class="pre">comment</span></code><a class="headerlink" href="#comment" title="Link to this heading">¶</a></h3>
<p>Ignores everything between <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">comment</span> <span class="pre">%}</span></code> and <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">endcomment</span> <span class="pre">%}</span></code>.
An optional note may be inserted in the first tag. For example, this is
useful when commenting out code for documenting why the code was disabled.</p>
<p>Sample usage:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>Rendered text with <span class="cp">{{</span> <span class="nv">pub_date</span><span class="o">|</span><span class="nf">date</span><span class="s2">:&quot;c&quot;</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">comment</span> <span class="s2">&quot;Optional note&quot;</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>Commented out text with <span class="cp">{{</span> <span class="nv">create_date</span><span class="o">|</span><span class="nf">date</span><span class="s2">:&quot;c&quot;</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endcomment</span> <span class="cp">%}</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">comment</span></code> tags cannot be nested.</p>
</section>
<section id="s-csrf-token">
<span id="s-std-templatetag-csrf_token"></span><span id="csrf-token"></span><span id="std-templatetag-csrf_token"></span><h3><code class="docutils literal notranslate"><span class="pre">csrf_token</span></code><a class="headerlink" href="#csrf-token" title="Link to this heading">¶</a></h3>
<p>This tag is used for CSRF protection, as described in the documentation for
<a class="reference internal" href="../csrf.html"><span class="doc">Cross Site Request Forgeries</span></a>.</p>
</section>
<section id="s-cycle">
<span id="s-std-templatetag-cycle"></span><span id="cycle"></span><span id="std-templatetag-cycle"></span><h3><code class="docutils literal notranslate"><span class="pre">cycle</span></code><a class="headerlink" href="#cycle" title="Link to this heading">¶</a></h3>
<p>Produces one of its arguments each time this tag is encountered. The first
argument is produced on the first encounter, the second argument on the second
encounter, and so forth. Once all arguments are exhausted, the tag cycles to
the first argument and produces it again.</p>
<p>This tag is particularly useful in a loop:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">for</span> <span class="nv">o</span> <span class="k">in</span> <span class="nv">some_list</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">tr</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">cycle</span> <span class="s1">&#39;row1&#39;</span> <span class="s1">&#39;row2&#39;</span> <span class="cp">%}</span><span class="s">&quot;</span><span class="p">&gt;</span>
        ...
    <span class="p">&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>The first iteration produces HTML that refers to class <code class="docutils literal notranslate"><span class="pre">row1</span></code>, the second to
<code class="docutils literal notranslate"><span class="pre">row2</span></code>, the third to <code class="docutils literal notranslate"><span class="pre">row1</span></code> again, and so on for each iteration of the
loop.</p>
<p>You can use variables, too. For example, if you have two template variables,
<code class="docutils literal notranslate"><span class="pre">rowvalue1</span></code> and <code class="docutils literal notranslate"><span class="pre">rowvalue2</span></code>, you can alternate between their values like
this:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">for</span> <span class="nv">o</span> <span class="k">in</span> <span class="nv">some_list</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">tr</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">cycle</span> <span class="nv">rowvalue1</span> <span class="nv">rowvalue2</span> <span class="cp">%}</span><span class="s">&quot;</span><span class="p">&gt;</span>
        ...
    <span class="p">&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Variables included in the cycle will be escaped. You can disable auto-escaping
with:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">for</span> <span class="nv">o</span> <span class="k">in</span> <span class="nv">some_list</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">tr</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">autoescape</span> <span class="nv">off</span> <span class="cp">%}{%</span> <span class="k">cycle</span> <span class="nv">rowvalue1</span> <span class="nv">rowvalue2</span> <span class="cp">%}{%</span> <span class="k">endautoescape</span> <span class="cp">%}</span><span class="s">&quot;</span><span class="p">&gt;</span>
        ...
    <span class="p">&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>You can mix variables and strings:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">for</span> <span class="nv">o</span> <span class="k">in</span> <span class="nv">some_list</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">tr</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">cycle</span> <span class="s1">&#39;row1&#39;</span> <span class="nv">rowvalue2</span> <span class="s1">&#39;row3&#39;</span> <span class="cp">%}</span><span class="s">&quot;</span><span class="p">&gt;</span>
        ...
    <span class="p">&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>In some cases you might want to refer to the current value of a cycle
without advancing to the next value. To do this,
give the <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">cycle</span> <span class="pre">%}</span></code> tag a name, using “as”, like this:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">cycle</span> <span class="s1">&#39;row1&#39;</span> <span class="s1">&#39;row2&#39;</span> <span class="k">as</span> <span class="nv">rowcolors</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>From then on, you can insert the current value of the cycle wherever you’d like
in your template by referencing the cycle name as a context variable. If you
want to move the cycle to the next value independently of the original
<code class="docutils literal notranslate"><span class="pre">cycle</span></code> tag, you can use another <code class="docutils literal notranslate"><span class="pre">cycle</span></code> tag and specify the name of the
variable. So, the following template:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">td</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">cycle</span> <span class="s1">&#39;row1&#39;</span> <span class="s1">&#39;row2&#39;</span> <span class="k">as</span> <span class="nv">rowcolors</span> <span class="cp">%}</span><span class="s">&quot;</span><span class="p">&gt;</span>...<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">td</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">rowcolors</span> <span class="cp">}}</span><span class="s">&quot;</span><span class="p">&gt;</span>...<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">td</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">cycle</span> <span class="nv">rowcolors</span> <span class="cp">%}</span><span class="s">&quot;</span><span class="p">&gt;</span>...<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">td</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">rowcolors</span> <span class="cp">}}</span><span class="s">&quot;</span><span class="p">&gt;</span>...<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>would output:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">td</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;row1&quot;</span><span class="p">&gt;</span>...<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">td</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;row1&quot;</span><span class="p">&gt;</span>...<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">td</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;row2&quot;</span><span class="p">&gt;</span>...<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">td</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;row2&quot;</span><span class="p">&gt;</span>...<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>You can use any number of values in a <code class="docutils literal notranslate"><span class="pre">cycle</span></code> tag, separated by spaces.
Values enclosed in single quotes (<code class="docutils literal notranslate"><span class="pre">'</span></code>) or double quotes (<code class="docutils literal notranslate"><span class="pre">&quot;</span></code>) are treated
as string literals, while values without quotes are treated as template
variables.</p>
<p>By default, when you use the <code class="docutils literal notranslate"><span class="pre">as</span></code> keyword with the cycle tag, the
usage of <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">cycle</span> <span class="pre">%}</span></code> that initiates the cycle will itself produce
the first value in the cycle. This could be a problem if you want to
use the value in a nested loop or an included template. If you only want
to declare the cycle but not produce the first value, you can add a
<code class="docutils literal notranslate"><span class="pre">silent</span></code> keyword as the last keyword in the tag. For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">for</span> <span class="nv">obj</span> <span class="k">in</span> <span class="nv">some_list</span> <span class="cp">%}</span>
    <span class="cp">{%</span> <span class="k">cycle</span> <span class="s1">&#39;row1&#39;</span> <span class="s1">&#39;row2&#39;</span> <span class="k">as</span> <span class="nv">rowcolors</span> <span class="nv">silent</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">tr</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">rowcolors</span> <span class="cp">}}</span><span class="s">&quot;</span><span class="p">&gt;</span><span class="cp">{%</span> <span class="k">include</span> <span class="s2">&quot;subtemplate.html&quot;</span> <span class="cp">%}</span><span class="p">&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>This will output a list of <code class="docutils literal notranslate"><span class="pre">&lt;tr&gt;</span></code> elements with <code class="docutils literal notranslate"><span class="pre">class</span></code>
alternating between <code class="docutils literal notranslate"><span class="pre">row1</span></code> and <code class="docutils literal notranslate"><span class="pre">row2</span></code>. The subtemplate will have
access to <code class="docutils literal notranslate"><span class="pre">rowcolors</span></code> in its context and the value will match the class
of the <code class="docutils literal notranslate"><span class="pre">&lt;tr&gt;</span></code> that encloses it. If the <code class="docutils literal notranslate"><span class="pre">silent</span></code> keyword were to be
omitted, <code class="docutils literal notranslate"><span class="pre">row1</span></code> and <code class="docutils literal notranslate"><span class="pre">row2</span></code> would be emitted as normal text, outside the
<code class="docutils literal notranslate"><span class="pre">&lt;tr&gt;</span></code> element.</p>
<p>When the silent keyword is used on a cycle definition, the silence
automatically applies to all subsequent uses of that specific cycle tag.
The following template would output <em>nothing</em>, even though the second
call to <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">cycle</span> <span class="pre">%}</span></code> doesn’t specify <code class="docutils literal notranslate"><span class="pre">silent</span></code>:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">cycle</span> <span class="s1">&#39;row1&#39;</span> <span class="s1">&#39;row2&#39;</span> <span class="k">as</span> <span class="nv">rowcolors</span> <span class="nv">silent</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">cycle</span> <span class="nv">rowcolors</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>You can use the <a class="reference internal" href="#std-templatetag-resetcycle"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">resetcycle</span></code></a> tag to make a <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">cycle</span> <span class="pre">%}</span></code> tag restart
from its first value when it’s next encountered.</p>
</section>
<section id="s-debug">
<span id="s-std-templatetag-debug"></span><span id="debug"></span><span id="std-templatetag-debug"></span><h3><code class="docutils literal notranslate"><span class="pre">debug</span></code><a class="headerlink" href="#debug" title="Link to this heading">¶</a></h3>
<p>Outputs a whole load of debugging information, including the current context
and imported modules. <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">debug</span> <span class="pre">%}</span></code> outputs nothing when the <a class="reference internal" href="../settings.html#std-setting-DEBUG"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEBUG</span></code></a>
setting is <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
</section>
<section id="s-extends">
<span id="s-std-templatetag-extends"></span><span id="extends"></span><span id="std-templatetag-extends"></span><h3><code class="docutils literal notranslate"><span class="pre">extends</span></code><a class="headerlink" href="#extends" title="Link to this heading">¶</a></h3>
<p>Signals that this template extends a parent template.</p>
<p>This tag can be used in two ways:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">extends</span> <span class="pre">&quot;base.html&quot;</span> <span class="pre">%}</span></code> (with quotes) uses the literal value
<code class="docutils literal notranslate"><span class="pre">&quot;base.html&quot;</span></code> as the name of the parent template to extend.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">extends</span> <span class="pre">variable</span> <span class="pre">%}</span></code> uses the value of <code class="docutils literal notranslate"><span class="pre">variable</span></code>. If the variable
evaluates to a string, Django will use that string as the name of the
parent template. If the variable evaluates to a <code class="docutils literal notranslate"><span class="pre">Template</span></code> object,
Django will use that object as the parent template.</p></li>
</ul>
<p>See <a class="reference internal" href="language.html#template-inheritance"><span class="std std-ref">Template inheritance</span></a> for more information.</p>
<p>Normally the template name is relative to the template loader’s root directory.
A string argument may also be a relative path starting with <code class="docutils literal notranslate"><span class="pre">./</span></code> or <code class="docutils literal notranslate"><span class="pre">../</span></code>.
For example, assume the following directory structure:</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>dir1/
    template.html
    base2.html
    my/
        base3.html
base1.html
</pre></div>
</div>
<p>In <code class="docutils literal notranslate"><span class="pre">template.html</span></code>, the following paths would be valid:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">extends</span> <span class="s2">&quot;./base2.html&quot;</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">extends</span> <span class="s2">&quot;../base1.html&quot;</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">extends</span> <span class="s2">&quot;./my/base3.html&quot;</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-filter">
<span id="s-std-templatetag-filter"></span><span id="filter"></span><span id="std-templatetag-filter"></span><h3><code class="docutils literal notranslate"><span class="pre">filter</span></code><a class="headerlink" href="#filter" title="Link to this heading">¶</a></h3>
<p>Filters the contents of the block through one or more filters. Multiple
filters can be specified with pipes and filters can have arguments, just as
in variable syntax.</p>
<p>Note that the block includes <em>all</em> the text between the <code class="docutils literal notranslate"><span class="pre">filter</span></code> and
<code class="docutils literal notranslate"><span class="pre">endfilter</span></code> tags.</p>
<p>Sample usage:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">filter</span> <span class="nf">force_escape</span><span class="o">|</span><span class="nf">lower</span> <span class="cp">%}</span>
    This text will be HTML-escaped, and will appear in all lowercase.
<span class="cp">{%</span> <span class="k">endfilter</span> <span class="cp">%}</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The <a class="reference internal" href="#std-templatefilter-escape"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">escape</span></code></a> and <a class="reference internal" href="#std-templatefilter-safe"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">safe</span></code></a> filters are not acceptable
arguments. Instead, use the <a class="reference internal" href="#std-templatetag-autoescape"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">autoescape</span></code></a> tag to manage autoescaping
for blocks of template code.</p>
</div>
</section>
<section id="s-firstof">
<span id="s-std-templatetag-firstof"></span><span id="firstof"></span><span id="std-templatetag-firstof"></span><h3><code class="docutils literal notranslate"><span class="pre">firstof</span></code><a class="headerlink" href="#firstof" title="Link to this heading">¶</a></h3>
<p>Outputs the first argument variable that is not “false” (i.e. exists, is not
empty, is not a false boolean value, and is not a zero numeric value). Outputs
nothing if all the passed variables are “false”.</p>
<p>Sample usage:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">firstof</span> <span class="nv">var1</span> <span class="nv">var2</span> <span class="nv">var3</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>This is equivalent to:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">var1</span> <span class="cp">%}</span>
    <span class="cp">{{</span> <span class="nv">var1</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">elif</span> <span class="nv">var2</span> <span class="cp">%}</span>
    <span class="cp">{{</span> <span class="nv">var2</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">elif</span> <span class="nv">var3</span> <span class="cp">%}</span>
    <span class="cp">{{</span> <span class="nv">var3</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>You can also use a literal string as a fallback value in case all
passed variables are False:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">firstof</span> <span class="nv">var1</span> <span class="nv">var2</span> <span class="nv">var3</span> <span class="s2">&quot;fallback value&quot;</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>This tag auto-escapes variable values. You can disable auto-escaping with:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">autoescape</span> <span class="nv">off</span> <span class="cp">%}</span>
    <span class="cp">{%</span> <span class="k">firstof</span> <span class="nv">var1</span> <span class="nv">var2</span> <span class="nv">var3</span> <span class="s2">&quot;&lt;strong&gt;fallback value&lt;/strong&gt;&quot;</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">endautoescape</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Or if only some variables should be escaped, you can use:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">firstof</span> <span class="nv">var1</span> <span class="nv">var2</span><span class="o">|</span><span class="nf">safe</span> <span class="nv">var3</span> <span class="s2">&quot;&lt;strong&gt;fallback value&lt;/strong&gt;&quot;</span><span class="o">|</span><span class="nf">safe</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>You can use the syntax <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">firstof</span> <span class="pre">var1</span> <span class="pre">var2</span> <span class="pre">var3</span> <span class="pre">as</span> <span class="pre">value</span> <span class="pre">%}</span></code> to store the
output inside a variable.</p>
</section>
<section id="s-for">
<span id="s-std-templatetag-for"></span><span id="for"></span><span id="std-templatetag-for"></span><h3><code class="docutils literal notranslate"><span class="pre">for</span></code><a class="headerlink" href="#for" title="Link to this heading">¶</a></h3>
<p>Loops over each item in an array, making the item available in a context
variable. For example, to display a list of athletes provided in
<code class="docutils literal notranslate"><span class="pre">athlete_list</span></code>:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">ul</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">for</span> <span class="nv">athlete</span> <span class="k">in</span> <span class="nv">athlete_list</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;</span><span class="cp">{{</span> <span class="nv">athlete.name</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">li</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
<span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>You can loop over a list in reverse by using
<code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">for</span> <span class="pre">obj</span> <span class="pre">in</span> <span class="pre">list</span> <span class="pre">reversed</span> <span class="pre">%}</span></code>.</p>
<p>If you need to loop over a list of lists, you can unpack the values
in each sublist into individual variables. For example, if your context
contains a list of (x,y) coordinates called <code class="docutils literal notranslate"><span class="pre">points</span></code>, you could use the
following to output the list of points:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">for</span> <span class="nv">x</span><span class="o">,</span> <span class="nv">y</span> <span class="k">in</span> <span class="nv">points</span> <span class="cp">%}</span>
    There is a point at <span class="cp">{{</span> <span class="nv">x</span> <span class="cp">}}</span>,<span class="cp">{{</span> <span class="nv">y</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>This can also be useful if you need to access the items in a dictionary.
For example, if your context contained a dictionary <code class="docutils literal notranslate"><span class="pre">data</span></code>, the following
would display the keys and values of the dictionary:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">for</span> <span class="nv">key</span><span class="o">,</span> <span class="nv">value</span> <span class="k">in</span> <span class="nv">data.items</span> <span class="cp">%}</span>
    <span class="cp">{{</span> <span class="nv">key</span> <span class="cp">}}</span>: <span class="cp">{{</span> <span class="nv">value</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Keep in mind that for the dot operator, dictionary key lookup takes precedence
over method lookup. Therefore if the <code class="docutils literal notranslate"><span class="pre">data</span></code> dictionary contains a key named
<code class="docutils literal notranslate"><span class="pre">'items'</span></code>, <code class="docutils literal notranslate"><span class="pre">data.items</span></code> will return <code class="docutils literal notranslate"><span class="pre">data['items']</span></code> instead of
<code class="docutils literal notranslate"><span class="pre">data.items()</span></code>. Avoid adding keys that are named like dictionary methods if
you want to use those methods in a template (<code class="docutils literal notranslate"><span class="pre">items</span></code>, <code class="docutils literal notranslate"><span class="pre">values</span></code>, <code class="docutils literal notranslate"><span class="pre">keys</span></code>,
etc.). Read more about the lookup order of the dot operator in the
<a class="reference internal" href="language.html#template-variables"><span class="std std-ref">documentation of template variables</span></a>.</p>
<p>The for loop sets a number of variables available within the loop:</p>
<table class="docutils">
<thead>
<tr class="row-odd"><th class="head"><p>Variable</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">forloop.counter</span></code></p></td>
<td><p>The current iteration of the loop (1-indexed)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">forloop.counter0</span></code></p></td>
<td><p>The current iteration of the loop (0-indexed)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">forloop.revcounter</span></code></p></td>
<td><p>The number of iterations from the end of the
loop (1-indexed)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">forloop.revcounter0</span></code></p></td>
<td><p>The number of iterations from the end of the
loop (0-indexed)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">forloop.first</span></code></p></td>
<td><p>True if this is the first time through the loop</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">forloop.last</span></code></p></td>
<td><p>True if this is the last time through the loop</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">forloop.length</span></code></p></td>
<td><p>The length of the loop</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">forloop.parentloop</span></code></p></td>
<td><p>For nested loops, this is the loop surrounding
the current one</p></td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<span class="title">Changed in Django 6.0:</span> <p>The variable <code class="docutils literal notranslate"><span class="pre">forloop.length</span></code> was added.</p>
</div>
</section>
<section id="s-for-empty">
<span id="for-empty"></span><h3><code class="docutils literal notranslate"><span class="pre">for</span></code> … <code class="docutils literal notranslate"><span class="pre">empty</span></code><a class="headerlink" href="#for-empty" title="Link to this heading">¶</a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">for</span></code> tag can take an optional <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">empty</span> <span class="pre">%}</span></code> clause whose text is
displayed if the given array is empty or could not be found:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">ul</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">for</span> <span class="nv">athlete</span> <span class="k">in</span> <span class="nv">athlete_list</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;</span><span class="cp">{{</span> <span class="nv">athlete.name</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">li</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">empty</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;</span>Sorry, no athletes in this list.<span class="p">&lt;/</span><span class="nt">li</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
<span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>The above is equivalent to – but shorter, cleaner, and possibly faster
than – the following:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">ul</span><span class="p">&gt;</span>
  <span class="cp">{%</span> <span class="k">if</span> <span class="nv">athlete_list</span> <span class="cp">%}</span>
    <span class="cp">{%</span> <span class="k">for</span> <span class="nv">athlete</span> <span class="k">in</span> <span class="nv">athlete_list</span> <span class="cp">%}</span>
      <span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;</span><span class="cp">{{</span> <span class="nv">athlete.name</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">li</span><span class="p">&gt;</span>
    <span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
  <span class="cp">{%</span> <span class="k">else</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;</span>Sorry, no athletes in this list.<span class="p">&lt;/</span><span class="nt">li</span><span class="p">&gt;</span>
  <span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
<span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span>
</pre></div>
</div>
</section>
<section id="s-if">
<span id="s-std-templatetag-if"></span><span id="if"></span><span id="std-templatetag-if"></span><h3><code class="docutils literal notranslate"><span class="pre">if</span></code><a class="headerlink" href="#if" title="Link to this heading">¶</a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">if</span> <span class="pre">%}</span></code> tag evaluates a variable, and if that variable is “true” (i.e.
exists, is not empty, and is not a false boolean value) the contents of the
block are output:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">athlete_list</span> <span class="cp">%}</span>
    Number of athletes: <span class="cp">{{</span> <span class="nv">athlete_list</span><span class="o">|</span><span class="nf">length</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">elif</span> <span class="nv">athlete_in_locker_room_list</span> <span class="cp">%}</span>
    Athletes should be out of the locker room soon!
<span class="cp">{%</span> <span class="k">else</span> <span class="cp">%}</span>
    No athletes.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>In the above, if <code class="docutils literal notranslate"><span class="pre">athlete_list</span></code> is not empty, the number of athletes will be
displayed by the <code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">athlete_list|length</span> <span class="pre">}}</span></code> variable.</p>
<p>As you can see, the <code class="docutils literal notranslate"><span class="pre">if</span></code> tag may take one or several <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">elif</span> <span class="pre">%}</span></code>
clauses, as well as an <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">else</span> <span class="pre">%}</span></code> clause that will be displayed if all
previous conditions fail. These clauses are optional.</p>
<section id="s-boolean-operators">
<span id="boolean-operators"></span><h4>Boolean operators<a class="headerlink" href="#boolean-operators" title="Link to this heading">¶</a></h4>
<p><a class="reference internal" href="#std-templatetag-if"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">if</span></code></a> tags may use <code class="docutils literal notranslate"><span class="pre">and</span></code>, <code class="docutils literal notranslate"><span class="pre">or</span></code> or <code class="docutils literal notranslate"><span class="pre">not</span></code> to test a number of
variables or to negate a given variable:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">athlete_list</span> <span class="k">and</span> <span class="nv">coach_list</span> <span class="cp">%}</span>
    Both athletes and coaches are available.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>

<span class="cp">{%</span> <span class="k">if</span> <span class="k">not</span> <span class="nv">athlete_list</span> <span class="cp">%}</span>
    There are no athletes.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>

<span class="cp">{%</span> <span class="k">if</span> <span class="nv">athlete_list</span> <span class="k">or</span> <span class="nv">coach_list</span> <span class="cp">%}</span>
    There are some athletes or some coaches.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>

<span class="cp">{%</span> <span class="k">if</span> <span class="k">not</span> <span class="nv">athlete_list</span> <span class="k">or</span> <span class="nv">coach_list</span> <span class="cp">%}</span>
    There are no athletes or there are some coaches.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>

<span class="cp">{%</span> <span class="k">if</span> <span class="nv">athlete_list</span> <span class="k">and</span> <span class="k">not</span> <span class="nv">coach_list</span> <span class="cp">%}</span>
    There are some athletes and absolutely no coaches.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Use of both <code class="docutils literal notranslate"><span class="pre">and</span></code> and <code class="docutils literal notranslate"><span class="pre">or</span></code> clauses within the same tag is allowed, with
<code class="docutils literal notranslate"><span class="pre">and</span></code> having higher precedence than <code class="docutils literal notranslate"><span class="pre">or</span></code> e.g.:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">athlete_list</span> <span class="k">and</span> <span class="nv">coach_list</span> <span class="k">or</span> <span class="nv">cheerleader_list</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>will be interpreted like:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="n">athlete_list</span> <span class="ow">and</span> <span class="n">coach_list</span><span class="p">)</span> <span class="ow">or</span> <span class="n">cheerleader_list</span><span class="p">:</span>
    <span class="o">...</span>
</pre></div>
</div>
<p>Use of actual parentheses in the <a class="reference internal" href="#std-templatetag-if"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">if</span></code></a> tag is invalid syntax. If you need
them to indicate precedence, you should use nested <a class="reference internal" href="#std-templatetag-if"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">if</span></code></a> tags.</p>
<p><a class="reference internal" href="#std-templatetag-if"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">if</span></code></a> tags may also use the operators <code class="docutils literal notranslate"><span class="pre">==</span></code>, <code class="docutils literal notranslate"><span class="pre">!=</span></code>, <code class="docutils literal notranslate"><span class="pre">&lt;</span></code>, <code class="docutils literal notranslate"><span class="pre">&gt;</span></code>,
<code class="docutils literal notranslate"><span class="pre">&lt;=</span></code>, <code class="docutils literal notranslate"><span class="pre">&gt;=</span></code>, <code class="docutils literal notranslate"><span class="pre">in</span></code>, <code class="docutils literal notranslate"><span class="pre">not</span> <span class="pre">in</span></code>, <code class="docutils literal notranslate"><span class="pre">is</span></code>, and <code class="docutils literal notranslate"><span class="pre">is</span> <span class="pre">not</span></code> which work as
follows:</p>
<section id="s-operator">
<span id="operator"></span><h5><code class="docutils literal notranslate"><span class="pre">==</span></code> operator<a class="headerlink" href="#operator" title="Link to this heading">¶</a></h5>
<p>Equality. Example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">somevar</span> <span class="o">==</span> <span class="s2">&quot;x&quot;</span> <span class="cp">%}</span>
  This appears if variable somevar equals the string &quot;x&quot;
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-id1">
<span id="id1"></span><h5><code class="docutils literal notranslate"><span class="pre">!=</span></code> operator<a class="headerlink" href="#id1" title="Link to this heading">¶</a></h5>
<p>Inequality. Example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">somevar</span> <span class="o">!=</span> <span class="s2">&quot;x&quot;</span> <span class="cp">%}</span>
  This appears if variable somevar does not equal the string &quot;x&quot;,
  or if somevar is not found in the context
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-id2">
<span id="id2"></span><h5><code class="docutils literal notranslate"><span class="pre">&lt;</span></code> operator<a class="headerlink" href="#id2" title="Link to this heading">¶</a></h5>
<p>Less than. Example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">somevar</span> <span class="o">&lt;</span> <span class="m">100</span> <span class="cp">%}</span>
  This appears if variable somevar is less than 100.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-id3">
<span id="id3"></span><h5><code class="docutils literal notranslate"><span class="pre">&gt;</span></code> operator<a class="headerlink" href="#id3" title="Link to this heading">¶</a></h5>
<p>Greater than. Example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">somevar</span> <span class="o">&gt;</span> <span class="m">0</span> <span class="cp">%}</span>
  This appears if variable somevar is greater than 0.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-id4">
<span id="id4"></span><h5><code class="docutils literal notranslate"><span class="pre">&lt;=</span></code> operator<a class="headerlink" href="#id4" title="Link to this heading">¶</a></h5>
<p>Less than or equal to. Example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">somevar</span> <span class="o">&lt;=</span> <span class="m">100</span> <span class="cp">%}</span>
  This appears if variable somevar is less than 100 or equal to 100.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-id5">
<span id="id5"></span><h5><code class="docutils literal notranslate"><span class="pre">&gt;=</span></code> operator<a class="headerlink" href="#id5" title="Link to this heading">¶</a></h5>
<p>Greater than or equal to. Example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">somevar</span> <span class="o">&gt;=</span> <span class="m">1</span> <span class="cp">%}</span>
  This appears if variable somevar is greater than 1 or equal to 1.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-in-operator">
<span id="in-operator"></span><h5><code class="docutils literal notranslate"><span class="pre">in</span></code> operator<a class="headerlink" href="#in-operator" title="Link to this heading">¶</a></h5>
<p>Contained within. This operator is supported by many Python containers to test
whether the given value is in the container. The following are some examples
of how <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">in</span> <span class="pre">y</span></code> will be interpreted:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="s2">&quot;bc&quot;</span> <span class="k">in</span> <span class="s2">&quot;abcdef&quot;</span> <span class="cp">%}</span>
  This appears since &quot;bc&quot; is a substring of &quot;abcdef&quot;
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>

<span class="cp">{%</span> <span class="k">if</span> <span class="s2">&quot;hello&quot;</span> <span class="k">in</span> <span class="nv">greetings</span> <span class="cp">%}</span>
  If greetings is a list or set, one element of which is the string
  &quot;hello&quot;, this will appear.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>

<span class="cp">{%</span> <span class="k">if</span> <span class="nv">user</span> <span class="k">in</span> <span class="nv">users</span> <span class="cp">%}</span>
  If users is a QuerySet, this will appear if user is an
  instance that belongs to the QuerySet.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-not-in-operator">
<span id="not-in-operator"></span><h5><code class="docutils literal notranslate"><span class="pre">not</span> <span class="pre">in</span></code> operator<a class="headerlink" href="#not-in-operator" title="Link to this heading">¶</a></h5>
<p>Not contained within. This is the negation of the <code class="docutils literal notranslate"><span class="pre">in</span></code> operator.</p>
</section>
<section id="s-is-operator">
<span id="is-operator"></span><h5><code class="docutils literal notranslate"><span class="pre">is</span></code> operator<a class="headerlink" href="#is-operator" title="Link to this heading">¶</a></h5>
<p>Object identity. Tests if two values are the same object. Example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">somevar</span> <span class="k">is</span> <span class="nf">True</span> <span class="cp">%}</span>
  This appears if and only if somevar is True.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>

<span class="cp">{%</span> <span class="k">if</span> <span class="nv">somevar</span> <span class="k">is</span> <span class="nf">None</span> <span class="cp">%}</span>
  This appears if somevar is None, or if somevar is not found in the context.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-is-not-operator">
<span id="is-not-operator"></span><h5><code class="docutils literal notranslate"><span class="pre">is</span> <span class="pre">not</span></code> operator<a class="headerlink" href="#is-not-operator" title="Link to this heading">¶</a></h5>
<p>Negated object identity. Tests if two values are not the same object. This is
the negation of the <code class="docutils literal notranslate"><span class="pre">is</span></code> operator. Example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">somevar</span> <span class="k">is</span> <span class="k">not</span> <span class="nf">True</span> <span class="cp">%}</span>
  This appears if somevar is not True, or if somevar is not found in the
  context.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>

<span class="cp">{%</span> <span class="k">if</span> <span class="nv">somevar</span> <span class="k">is</span> <span class="k">not</span> <span class="nf">None</span> <span class="cp">%}</span>
  This appears if and only if somevar is not None.
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
</section>
<section id="s-filters">
<span id="filters"></span><h4>Filters<a class="headerlink" href="#filters" title="Link to this heading">¶</a></h4>
<p>You can also use filters in the <a class="reference internal" href="#std-templatetag-if"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">if</span></code></a> expression. For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">messages</span><span class="o">|</span><span class="nf">length</span> <span class="o">&gt;=</span> <span class="m">100</span> <span class="cp">%}</span>
   You have lots of messages today!
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-complex-expressions">
<span id="complex-expressions"></span><h4>Complex expressions<a class="headerlink" href="#complex-expressions" title="Link to this heading">¶</a></h4>
<p>All of the above can be combined to form complex expressions. For such
expressions, it can be important to know how the operators are grouped when the
expression is evaluated - that is, the precedence rules. The precedence of the
operators, from lowest to highest, is as follows:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">or</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">and</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">not</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">in</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">==</span></code>, <code class="docutils literal notranslate"><span class="pre">!=</span></code>, <code class="docutils literal notranslate"><span class="pre">&lt;</span></code>, <code class="docutils literal notranslate"><span class="pre">&gt;</span></code>, <code class="docutils literal notranslate"><span class="pre">&lt;=</span></code>, <code class="docutils literal notranslate"><span class="pre">&gt;=</span></code></p></li>
</ul>
<p>(This follows Python exactly). So, for example, the following complex
<a class="reference internal" href="#std-templatetag-if"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">if</span></code></a> tag:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">a</span> <span class="o">==</span> <span class="nv">b</span> <span class="k">or</span> <span class="nv">c</span> <span class="o">==</span> <span class="nv">d</span> <span class="k">and</span> <span class="nv">e</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>…will be interpreted as:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">a</span> <span class="o">==</span> <span class="n">b</span><span class="p">)</span> <span class="ow">or</span> <span class="p">((</span><span class="n">c</span> <span class="o">==</span> <span class="n">d</span><span class="p">)</span> <span class="ow">and</span> <span class="n">e</span><span class="p">)</span>
</pre></div>
</div>
<p>If you need different precedence, you will need to use nested <a class="reference internal" href="#std-templatetag-if"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">if</span></code></a> tags.
Sometimes that is better for clarity anyway, for the sake of those who do not
know the precedence rules.</p>
<p>The comparison operators cannot be ‘chained’ like in Python or in mathematical
notation. For example, instead of using:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">a</span> <span class="o">&gt;</span> <span class="nv">b</span> <span class="o">&gt;</span> <span class="nv">c</span> <span class="cp">%}</span>  (WRONG)
</pre></div>
</div>
<p>you should use:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">if</span> <span class="nv">a</span> <span class="o">&gt;</span> <span class="nv">b</span> <span class="k">and</span> <span class="nv">b</span> <span class="o">&gt;</span> <span class="nv">c</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
</section>
<section id="s-ifchanged">
<span id="s-std-templatetag-ifchanged"></span><span id="ifchanged"></span><span id="std-templatetag-ifchanged"></span><h3><code class="docutils literal notranslate"><span class="pre">ifchanged</span></code><a class="headerlink" href="#ifchanged" title="Link to this heading">¶</a></h3>
<p>Check if a value has changed from the last iteration of a loop.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">ifchanged</span> <span class="pre">%}</span></code> block tag is used within a loop. It has two possible
uses.</p>
<ol class="arabic">
<li><p>Checks its own rendered contents against its previous state and only
displays the content if it has changed. For example, this displays a list of
days, only displaying the month if it changes:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">h1</span><span class="p">&gt;</span>Archive for <span class="cp">{{</span> <span class="nv">year</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">h1</span><span class="p">&gt;</span>

<span class="cp">{%</span> <span class="k">for</span> <span class="nv">date</span> <span class="k">in</span> <span class="nv">days</span> <span class="cp">%}</span>
    <span class="cp">{%</span> <span class="k">ifchanged</span> <span class="cp">%}</span><span class="p">&lt;</span><span class="nt">h3</span><span class="p">&gt;</span><span class="cp">{{</span> <span class="nv">date</span><span class="o">|</span><span class="nf">date</span><span class="s2">:&quot;F&quot;</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">h3</span><span class="p">&gt;</span><span class="cp">{%</span> <span class="k">endifchanged</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">date</span><span class="o">|</span><span class="nf">date</span><span class="s2">:&quot;M/d&quot;</span><span class="o">|</span><span class="nf">lower</span> <span class="cp">}}</span><span class="s">/&quot;</span><span class="p">&gt;</span><span class="cp">{{</span> <span class="nv">date</span><span class="o">|</span><span class="nf">date</span><span class="s2">:&quot;j&quot;</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
</li>
<li><p>If given one or more variables, check whether any variable has changed.
For example, the following shows the date every time it changes, while
showing the hour if either the hour or the date has changed:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">for</span> <span class="nv">date</span> <span class="k">in</span> <span class="nv">days</span> <span class="cp">%}</span>
    <span class="cp">{%</span> <span class="k">ifchanged</span> <span class="nv">date.date</span> <span class="cp">%}</span> <span class="cp">{{</span> <span class="nv">date.date</span> <span class="cp">}}</span> <span class="cp">{%</span> <span class="k">endifchanged</span> <span class="cp">%}</span>
    <span class="cp">{%</span> <span class="k">ifchanged</span> <span class="nv">date.hour</span> <span class="nv">date.date</span> <span class="cp">%}</span>
        <span class="cp">{{</span> <span class="nv">date.hour</span> <span class="cp">}}</span>
    <span class="cp">{%</span> <span class="k">endifchanged</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
</li>
</ol>
<p>The <code class="docutils literal notranslate"><span class="pre">ifchanged</span></code> tag can also take an optional <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">else</span> <span class="pre">%}</span></code> clause that
will be displayed if the value has not changed:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">for</span> <span class="nv">match</span> <span class="k">in</span> <span class="nv">matches</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">div</span> <span class="na">style</span><span class="o">=</span><span class="s">&quot;background-color:</span>
<span class="s">        </span><span class="cp">{%</span> <span class="k">ifchanged</span> <span class="nv">match.ballot_id</span> <span class="cp">%}</span>
<span class="s">            </span><span class="cp">{%</span> <span class="k">cycle</span> <span class="s2">&quot;red&quot;</span> <span class="s2">&quot;blue&quot;</span> <span class="cp">%}</span>
<span class="s">        </span><span class="cp">{%</span> <span class="k">else</span> <span class="cp">%}</span>
<span class="s">            gray</span>
<span class="s">        </span><span class="cp">{%</span> <span class="k">endifchanged</span> <span class="cp">%}</span>
<span class="s">    &quot;</span><span class="p">&gt;</span><span class="cp">{{</span> <span class="nv">match</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">div</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-include">
<span id="s-std-templatetag-include"></span><span id="include"></span><span id="std-templatetag-include"></span><h3><code class="docutils literal notranslate"><span class="pre">include</span></code><a class="headerlink" href="#include" title="Link to this heading">¶</a></h3>
<p>Loads a template and renders it with the current context. This is a way of
“including” other templates within a template.</p>
<p>The template name can either be a variable or a hardcoded (quoted) string,
in either single or double quotes.</p>
<p>This example includes the contents of the template <code class="docutils literal notranslate"><span class="pre">&quot;foo/bar.html&quot;</span></code>:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">include</span> <span class="s2">&quot;foo/bar.html&quot;</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Normally the template name is relative to the template loader’s root directory.
A string argument may also be a relative path starting with <code class="docutils literal notranslate"><span class="pre">./</span></code> or <code class="docutils literal notranslate"><span class="pre">../</span></code>
as described in the <a class="reference internal" href="#std-templatetag-extends"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">extends</span></code></a> tag.</p>
<p>This example includes the contents of the template whose name is contained in
the variable <code class="docutils literal notranslate"><span class="pre">template_name</span></code>:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">include</span> <span class="nv">template_name</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>The variable may also be any object with a <code class="docutils literal notranslate"><span class="pre">render()</span></code> method that accepts a
context. This allows you to reference a compiled <code class="docutils literal notranslate"><span class="pre">Template</span></code> in your context.</p>
<p>Additionally, the variable may be an iterable of template names, in which case
the first that can be loaded will be used, as per
<a class="reference internal" href="../../topics/templates.html#django.template.loader.select_template" title="django.template.loader.select_template"><code class="xref py py-func docutils literal notranslate"><span class="pre">select_template()</span></code></a>.</p>
<p>An included template is rendered within the context of the template that
includes it. This example produces the output <code class="docutils literal notranslate"><span class="pre">&quot;Hello,</span> <span class="pre">John!&quot;</span></code>:</p>
<ul>
<li><p>Context: variable <code class="docutils literal notranslate"><span class="pre">person</span></code> is set to <code class="docutils literal notranslate"><span class="pre">&quot;John&quot;</span></code> and variable <code class="docutils literal notranslate"><span class="pre">greeting</span></code>
is set to <code class="docutils literal notranslate"><span class="pre">&quot;Hello&quot;</span></code>.</p></li>
<li><p>Template:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">include</span> <span class="s2">&quot;name_snippet.html&quot;</span> <span class="cp">%}</span>
</pre></div>
</div>
</li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">name_snippet.html</span></code> template:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">greeting</span> <span class="cp">}}</span>, <span class="cp">{{</span> <span class="nv">person</span><span class="o">|</span><span class="nf">default</span><span class="s2">:&quot;friend&quot;</span> <span class="cp">}}</span>!
</pre></div>
</div>
</li>
</ul>
<p>You can pass additional context to the template using keyword arguments:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">include</span> <span class="s2">&quot;name_snippet.html&quot;</span> <span class="k">with</span> <span class="nv">person</span><span class="o">=</span><span class="s2">&quot;Jane&quot;</span> <span class="nv">greeting</span><span class="o">=</span><span class="s2">&quot;Hello&quot;</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>If you want to render the context only with the variables provided (or even
no variables at all), use the <code class="docutils literal notranslate"><span class="pre">only</span></code> option. No other variables are
available to the included template:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">include</span> <span class="s2">&quot;name_snippet.html&quot;</span> <span class="k">with</span> <span class="nv">greeting</span><span class="o">=</span><span class="s2">&quot;Hi&quot;</span> <span class="nv">only</span> <span class="cp">%}</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The <a class="reference internal" href="#std-templatetag-include"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">include</span></code></a> tag should be considered as an implementation of
“render this subtemplate and include the HTML”, not as “parse this
subtemplate and include its contents as if it were part of the parent”.
This means that there is no shared state between included templates –
each include is a completely independent rendering process.</p>
<p>Blocks are evaluated <em>before</em> they are included. This means that a template
that includes blocks from another will contain blocks that have <em>already
been evaluated and rendered</em> - not blocks that can be overridden by, for
example, an extending template.</p>
</div>
</section>
<section id="s-load">
<span id="s-std-templatetag-load"></span><span id="load"></span><span id="std-templatetag-load"></span><h3><code class="docutils literal notranslate"><span class="pre">load</span></code><a class="headerlink" href="#load" title="Link to this heading">¶</a></h3>
<p>Loads a custom template tag set.</p>
<p>For example, the following template would load all the tags and filters
registered in <code class="docutils literal notranslate"><span class="pre">somelibrary</span></code> and <code class="docutils literal notranslate"><span class="pre">otherlibrary</span></code> located in package
<code class="docutils literal notranslate"><span class="pre">package</span></code>:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">load</span> <span class="nv">somelibrary</span> <span class="nv">package.otherlibrary</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>You can also selectively load individual filters or tags from a library, using
the <code class="docutils literal notranslate"><span class="pre">from</span></code> argument. In this example, the template tags/filters named <code class="docutils literal notranslate"><span class="pre">foo</span></code>
and <code class="docutils literal notranslate"><span class="pre">bar</span></code> will be loaded from <code class="docutils literal notranslate"><span class="pre">somelibrary</span></code>:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">load</span> <span class="nv">foo</span> <span class="nv">bar</span> <span class="nv">from</span> <span class="nv">somelibrary</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>See <a class="reference internal" href="../../howto/custom-template-tags.html"><span class="doc">Custom tag and filter libraries</span></a> for
more information.</p>
</section>
<section id="s-lorem">
<span id="s-std-templatetag-lorem"></span><span id="lorem"></span><span id="std-templatetag-lorem"></span><h3><code class="docutils literal notranslate"><span class="pre">lorem</span></code><a class="headerlink" href="#lorem" title="Link to this heading">¶</a></h3>
<p>Displays random “lorem ipsum” Latin text. This is useful for providing sample
data in templates.</p>
<p>Usage:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">lorem</span> <span class="o">[</span><span class="nv">count</span><span class="o">]</span> <span class="o">[</span><span class="nv">method</span><span class="o">]</span> <span class="o">[</span><span class="nv">random</span><span class="o">]</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">lorem</span> <span class="pre">%}</span></code> tag can be used with zero, one, two or three arguments.
The arguments are:</p>
<table class="docutils">
<thead>
<tr class="row-odd"><th class="head"><p>Argument</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">count</span></code></p></td>
<td><p>A number (or variable) containing the number of paragraphs or
words to generate (default is 1).</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">method</span></code></p></td>
<td><p>Either <code class="docutils literal notranslate"><span class="pre">w</span></code> for words, <code class="docutils literal notranslate"><span class="pre">p</span></code> for HTML paragraphs or <code class="docutils literal notranslate"><span class="pre">b</span></code>
for plain-text paragraph blocks (default is <code class="docutils literal notranslate"><span class="pre">b</span></code>).</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">random</span></code></p></td>
<td><p>The word <code class="docutils literal notranslate"><span class="pre">random</span></code>, which if given, does not use the common
paragraph (“Lorem ipsum dolor sit amet…”) when generating
text.</p></td>
</tr>
</tbody>
</table>
<p>Examples:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">lorem</span> <span class="pre">%}</span></code> will output the common “lorem ipsum” paragraph.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">lorem</span> <span class="pre">3</span> <span class="pre">p</span> <span class="pre">%}</span></code> will output the common “lorem ipsum” paragraph
and two random paragraphs each wrapped in HTML <code class="docutils literal notranslate"><span class="pre">&lt;p&gt;</span></code> tags.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">lorem</span> <span class="pre">2</span> <span class="pre">w</span> <span class="pre">random</span> <span class="pre">%}</span></code> will output two random Latin words.</p></li>
</ul>
</section>
<section id="s-now">
<span id="s-std-templatetag-now"></span><span id="now"></span><span id="std-templatetag-now"></span><h3><code class="docutils literal notranslate"><span class="pre">now</span></code><a class="headerlink" href="#now" title="Link to this heading">¶</a></h3>
<p>Displays the current date and/or time, using a format according to the given
string. Such string can contain format specifiers characters as described
in the <a class="reference internal" href="#std-templatefilter-date"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">date</span></code></a> filter section.</p>
<p>Example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>It is <span class="cp">{%</span> <span class="k">now</span> <span class="s2">&quot;jS F Y H:i&quot;</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Note that you can backslash-escape a format string if you want to use the
“raw” value. In this example, both “o” and “f” are backslash-escaped, because
otherwise each is a format string that displays the year and the time,
respectively:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>It is the <span class="cp">{%</span> <span class="k">now</span> <span class="s2">&quot;jS \o\f F&quot;</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>This would display as “It is the 4th of September”.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The format passed can also be one of the predefined ones
<a class="reference internal" href="../settings.html#std-setting-DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATE_FORMAT</span></code></a>, <a class="reference internal" href="../settings.html#std-setting-DATETIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATETIME_FORMAT</span></code></a>,
<a class="reference internal" href="../settings.html#std-setting-SHORT_DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SHORT_DATE_FORMAT</span></code></a> or <a class="reference internal" href="../settings.html#std-setting-SHORT_DATETIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SHORT_DATETIME_FORMAT</span></code></a>.
The predefined formats may vary depending on the current locale and
if <a class="reference internal" href="../../topics/i18n/formatting.html"><span class="doc">Format localization</span></a> is enabled, e.g.:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>It is <span class="cp">{%</span> <span class="k">now</span> <span class="s2">&quot;SHORT_DATETIME_FORMAT&quot;</span> <span class="cp">%}</span>
</pre></div>
</div>
</div>
<p>You can also use the syntax <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">now</span> <span class="pre">&quot;Y&quot;</span> <span class="pre">as</span> <span class="pre">current_year</span> <span class="pre">%}</span></code> to store the
output (as a string) inside a variable. This is useful if you want to use
<code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">now</span> <span class="pre">%}</span></code> inside a template tag like <a class="reference internal" href="../../topics/i18n/translation.html#std-templatetag-blocktranslate"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">blocktranslate</span></code></a> for example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">now</span> <span class="s2">&quot;Y&quot;</span> <span class="k">as</span> <span class="nv">current_year</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">blocktranslate</span> <span class="cp">%}</span>Copyright <span class="cp">{{</span> <span class="nv">current_year</span> <span class="cp">}}{%</span> <span class="k">endblocktranslate</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-partial">
<span id="s-std-templatetag-partial"></span><span id="partial"></span><span id="std-templatetag-partial"></span><h3><code class="docutils literal notranslate"><span class="pre">partial</span></code><a class="headerlink" href="#partial" title="Link to this heading">¶</a></h3>
<div class="versionadded">
<span class="title">New in Django 6.0.</span> </div>
<p>Renders a template fragment that was defined with <a class="reference internal" href="#std-templatetag-partialdef"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">partialdef</span></code></a>, inserting
the matching partial at this location.</p>
<p>Usage:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">partial</span> <span class="nv">partial_name</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">partial_name</span></code> argument is the name of the template fragment to render.</p>
<p>In the following example, a partial named <code class="docutils literal notranslate"><span class="pre">button</span></code> is defined and then
rendered three times:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">partialdef</span> <span class="nv">button</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">button</span><span class="p">&gt;</span>Submit<span class="p">&lt;/</span><span class="nt">button</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endpartialdef</span> <span class="cp">%}</span>

<span class="cp">{%</span> <span class="k">partial</span> <span class="nv">button</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">partial</span> <span class="nv">button</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">partial</span> <span class="nv">button</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-partialdef">
<span id="s-std-templatetag-partialdef"></span><span id="partialdef"></span><span id="std-templatetag-partialdef"></span><h3><code class="docutils literal notranslate"><span class="pre">partialdef</span></code><a class="headerlink" href="#partialdef" title="Link to this heading">¶</a></h3>
<div class="versionadded">
<span class="title">New in Django 6.0.</span> </div>
<p>Defines a reusable template fragment that can be rendered multiple times within
the same template or accessed directly via <a class="reference internal" href="language.html#template-partials-direct-access"><span class="std std-ref">template loading or inclusion</span></a>.</p>
<p>Usage:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">partialdef</span> <span class="nv">partial_name</span> <span class="cp">%}</span>
    <span class="c">{# Reusable content. #}</span>
<span class="cp">{%</span> <span class="k">endpartialdef</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">partial_name</span></code> argument is required and must be a valid template
identifier.</p>
<p>In the following example, a new fragment named <code class="docutils literal notranslate"><span class="pre">card</span></code> is defined:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">partialdef</span> <span class="nv">card</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">div</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;card&quot;</span><span class="p">&gt;</span>
        <span class="p">&lt;</span><span class="nt">h3</span><span class="p">&gt;</span><span class="cp">{{</span> <span class="nv">title</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">h3</span><span class="p">&gt;</span>
        <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span><span class="cp">{{</span> <span class="nv">content</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
    <span class="p">&lt;/</span><span class="nt">div</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endpartialdef</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>This partial can then be rendered using the <a class="reference internal" href="#std-templatetag-partial"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">partial</span></code></a> tag:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">partial</span> <span class="nv">card</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">partial</span> <span class="nv">card</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>To <a class="reference internal" href="language.html#template-partials-inline"><span class="std std-ref">render a fragment immediately in place</span></a>,
use the <code class="docutils literal notranslate"><span class="pre">inline</span></code> option. The partial is still stored and can be reused later.</p>
</section>
<section id="s-querystring">
<span id="s-std-templatetag-querystring"></span><span id="querystring"></span><span id="std-templatetag-querystring"></span><h3><code class="docutils literal notranslate"><span class="pre">querystring</span></code><a class="headerlink" href="#querystring" title="Link to this heading">¶</a></h3>
<p>Outputs a URL-encoded formatted query string based on the provided parameters.</p>
<p>This tag accepts positional arguments, which must be mappings (such as
<a class="reference internal" href="../request-response.html#django.http.QueryDict" title="django.http.QueryDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">QueryDict</span></code></a> or <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.14)"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a>). If no positional arguments
are provided, <a class="reference internal" href="../request-response.html#django.http.HttpRequest.GET" title="django.http.HttpRequest.GET"><code class="xref py py-attr docutils literal notranslate"><span class="pre">request.GET</span></code></a> is used as the
default to construct the query string.</p>
<p>Positional arguments are processed sequentially, while keyword arguments are
treated as key-value pairs, applied last. Later arguments take precedence over
earlier ones, ensuring the most recent pairs are reflected in the final result.</p>
<p>The result always includes a leading <code class="docutils literal notranslate"><span class="pre">&quot;?&quot;</span></code> since this tag is mainly used for
links, and an empty result could prevent the page from reloading as expected.</p>
<div class="admonition-using-request-get-as-default admonition">
<p class="admonition-title">Using <code class="docutils literal notranslate"><span class="pre">request.GET</span></code> as default</p>
<p>To use <code class="docutils literal notranslate"><span class="pre">request.GET</span></code> as the default <code class="docutils literal notranslate"><span class="pre">QueryDict</span></code> instance, the
<code class="docutils literal notranslate"><span class="pre">django.template.context_processors.request</span></code> context processor should be
enabled. If it’s not enabled, you must either explicitly pass the
<code class="docutils literal notranslate"><span class="pre">request</span></code> object into the template context, or provide a <code class="docutils literal notranslate"><span class="pre">QueryDict</span></code>
instance to this tag.</p>
</div>
<div class="versionchanged">
<span class="title">Changed in Django 6.0:</span> <p>A <code class="docutils literal notranslate"><span class="pre">?</span></code> was prepended to the query string for empty results.</p>
</div>
<section id="s-basic-usage">
<span id="basic-usage"></span><h4>Basic usage<a class="headerlink" href="#basic-usage" title="Link to this heading">¶</a></h4>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">querystring</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Outputs the current query string verbatim. So if the query string in the
request is <code class="docutils literal notranslate"><span class="pre">?color=green</span></code>, the output would be <code class="docutils literal notranslate"><span class="pre">?color=green</span></code>. If the
current query string is empty, the output will be <code class="docutils literal notranslate"><span class="pre">?</span></code>.</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">querystring</span> <span class="nv">size</span><span class="o">=</span><span class="s2">&quot;M&quot;</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Outputs the current query string with the addition of the <code class="docutils literal notranslate"><span class="pre">size</span></code> parameter.
Following the previous example, the output would be <code class="docutils literal notranslate"><span class="pre">?color=green&amp;size=M</span></code>.</p>
</section>
<section id="s-setting-items">
<span id="setting-items"></span><h4>Setting items<a class="headerlink" href="#setting-items" title="Link to this heading">¶</a></h4>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">querystring</span> <span class="nv">color</span><span class="o">=</span><span class="s2">&quot;red&quot;</span> <span class="nv">size</span><span class="o">=</span><span class="s2">&quot;S&quot;</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Adds or modifies parameters in the query string. Each keyword argument will be
added to the query string, replacing any existing value for that key. For
instance, if the current query string is <code class="docutils literal notranslate"><span class="pre">?color=green</span></code>, the output will be
<code class="docutils literal notranslate"><span class="pre">?color=red&amp;size=S</span></code>.</p>
</section>
<section id="s-removing-items">
<span id="removing-items"></span><h4>Removing items<a class="headerlink" href="#removing-items" title="Link to this heading">¶</a></h4>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">querystring</span> <span class="nv">color</span><span class="o">=</span><span class="kp">None</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Passing <code class="docutils literal notranslate"><span class="pre">None</span></code> as the value removes the parameter from the query string. For
example, if the current query string is <code class="docutils literal notranslate"><span class="pre">?color=green&amp;size=M</span></code>, the output
will be <code class="docutils literal notranslate"><span class="pre">?size=M</span></code>.</p>
</section>
<section id="s-handling-lists">
<span id="handling-lists"></span><h4>Handling lists<a class="headerlink" href="#handling-lists" title="Link to this heading">¶</a></h4>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">querystring</span> <span class="nv">color</span><span class="o">=</span><span class="nv">my_list</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">my_list</span></code> is <code class="docutils literal notranslate"><span class="pre">[&quot;red&quot;,</span> <span class="pre">&quot;blue&quot;]</span></code>, the output will be
<code class="docutils literal notranslate"><span class="pre">?color=red&amp;color=blue</span></code>, preserving the list structure in the query string.</p>
</section>
<section id="s-customizing-the-base-querydict">
<span id="customizing-the-base-querydict"></span><h4>Customizing the base QueryDict<a class="headerlink" href="#customizing-the-base-querydict" title="Link to this heading">¶</a></h4>
<p>You can pass custom <code class="docutils literal notranslate"><span class="pre">QueryDict</span></code> or <code class="docutils literal notranslate"><span class="pre">dict</span></code> instances as positional arguments
to replace <code class="docutils literal notranslate"><span class="pre">request.GET</span></code>. When multiple arguments are provided, key-value
pairs from later arguments take precedence over earlier ones.</p>
<p>For example, if <code class="docutils literal notranslate"><span class="pre">my_query_dict</span></code> is <code class="docutils literal notranslate"><span class="pre">&lt;QueryDict:</span> <span class="pre">{'color':</span> <span class="pre">['blue'],</span> <span class="pre">'size':</span>
<span class="pre">['S']}&gt;</span></code> and <code class="docutils literal notranslate"><span class="pre">my_dict</span></code> is <code class="docutils literal notranslate"><span class="pre">{'color':</span> <span class="pre">'orange',</span> <span class="pre">'fabric':</span> <span class="pre">'silk',</span> <span class="pre">'type':</span>
<span class="pre">'dress'}</span></code>, this outputs <code class="docutils literal notranslate"><span class="pre">?color=orange&amp;size=S&amp;fabric=silk</span></code>.</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">querystring</span> <span class="nv">my_query_dict</span> <span class="nv">my_dict</span> <span class="nv">size</span><span class="o">=</span><span class="s2">&quot;S&quot;</span> <span class="nv">type</span><span class="o">=</span><span class="kp">None</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>If all keys are removed by setting them to <code class="docutils literal notranslate"><span class="pre">None</span></code>, this outputs <code class="docutils literal notranslate"><span class="pre">?</span></code>:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">querystring</span> <span class="nv">my_query_dict</span> <span class="nv">my_dict</span> <span class="nv">color</span><span class="o">=</span><span class="kp">None</span> <span class="nv">size</span><span class="o">=</span><span class="kp">None</span> <span class="nv">fabric</span><span class="o">=</span><span class="kp">None</span> <span class="nv">type</span><span class="o">=</span><span class="kp">None</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Similarly, if all positional arguments are empty and keyword arguments do not
contribute any new params, the output will also be <code class="docutils literal notranslate"><span class="pre">?</span></code>.</p>
<div class="versionchanged">
<span class="title">Changed in Django 6.0:</span> <p>Support for multiple positional mapping arguments was added.</p>
</div>
</section>
<section id="s-dynamic-usage">
<span id="dynamic-usage"></span><h4>Dynamic usage<a class="headerlink" href="#dynamic-usage" title="Link to this heading">¶</a></h4>
<p>A common example of using this tag is to preserve the current query string when
displaying a page of results, while adding a link to the next and previous
pages of results. For example, if the paginator is currently on page 3, and the
current query string is <code class="docutils literal notranslate"><span class="pre">?color=blue&amp;size=M&amp;page=3</span></code>, the following code would
output <code class="docutils literal notranslate"><span class="pre">?color=blue&amp;size=M&amp;page=4</span></code>:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">querystring</span> <span class="nv">page</span><span class="o">=</span><span class="nv">page.next_page_number</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>You can also store the value in a variable. For example, if you need multiple
links to the same page, define it as:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">querystring</span> <span class="nv">page</span><span class="o">=</span><span class="nv">page.next_page_number</span> <span class="k">as</span> <span class="nv">next_page</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
</section>
<section id="s-regroup">
<span id="s-std-templatetag-regroup"></span><span id="regroup"></span><span id="std-templatetag-regroup"></span><h3><code class="docutils literal notranslate"><span class="pre">regroup</span></code><a class="headerlink" href="#regroup" title="Link to this heading">¶</a></h3>
<p>Regroups a list of alike objects by a common attribute.</p>
<p>This complex tag is best illustrated by way of an example: say that <code class="docutils literal notranslate"><span class="pre">cities</span></code>
is a list of cities represented by dictionaries containing <code class="docutils literal notranslate"><span class="pre">&quot;name&quot;</span></code>,
<code class="docutils literal notranslate"><span class="pre">&quot;population&quot;</span></code>, and <code class="docutils literal notranslate"><span class="pre">&quot;country&quot;</span></code> keys:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">cities</span> <span class="o">=</span> <span class="p">[</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Mumbai&quot;</span><span class="p">,</span> <span class="s2">&quot;population&quot;</span><span class="p">:</span> <span class="s2">&quot;19,000,000&quot;</span><span class="p">,</span> <span class="s2">&quot;country&quot;</span><span class="p">:</span> <span class="s2">&quot;India&quot;</span><span class="p">},</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Calcutta&quot;</span><span class="p">,</span> <span class="s2">&quot;population&quot;</span><span class="p">:</span> <span class="s2">&quot;15,000,000&quot;</span><span class="p">,</span> <span class="s2">&quot;country&quot;</span><span class="p">:</span> <span class="s2">&quot;India&quot;</span><span class="p">},</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;New York&quot;</span><span class="p">,</span> <span class="s2">&quot;population&quot;</span><span class="p">:</span> <span class="s2">&quot;20,000,000&quot;</span><span class="p">,</span> <span class="s2">&quot;country&quot;</span><span class="p">:</span> <span class="s2">&quot;USA&quot;</span><span class="p">},</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Chicago&quot;</span><span class="p">,</span> <span class="s2">&quot;population&quot;</span><span class="p">:</span> <span class="s2">&quot;7,000,000&quot;</span><span class="p">,</span> <span class="s2">&quot;country&quot;</span><span class="p">:</span> <span class="s2">&quot;USA&quot;</span><span class="p">},</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Tokyo&quot;</span><span class="p">,</span> <span class="s2">&quot;population&quot;</span><span class="p">:</span> <span class="s2">&quot;33,000,000&quot;</span><span class="p">,</span> <span class="s2">&quot;country&quot;</span><span class="p">:</span> <span class="s2">&quot;Japan&quot;</span><span class="p">},</span>
<span class="p">]</span>
</pre></div>
</div>
<p>…and you’d like to display a hierarchical list that is ordered by country,
like this:</p>
<ul class="simple">
<li><p>India</p>
<ul>
<li><p>Mumbai: 19,000,000</p></li>
<li><p>Calcutta: 15,000,000</p></li>
</ul>
</li>
<li><p>USA</p>
<ul>
<li><p>New York: 20,000,000</p></li>
<li><p>Chicago: 7,000,000</p></li>
</ul>
</li>
<li><p>Japan</p>
<ul>
<li><p>Tokyo: 33,000,000</p></li>
</ul>
</li>
</ul>
<p>You can use the <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">regroup</span> <span class="pre">%}</span></code> tag to group the list of cities by country.
The following snippet of template code would accomplish this:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">regroup</span> <span class="nv">cities</span> <span class="nv">by</span> <span class="nv">country</span> <span class="k">as</span> <span class="nv">country_list</span> <span class="cp">%}</span>

<span class="p">&lt;</span><span class="nt">ul</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">for</span> <span class="nv">country</span> <span class="k">in</span> <span class="nv">country_list</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;</span><span class="cp">{{</span> <span class="nv">country.grouper</span> <span class="cp">}}</span>
    <span class="p">&lt;</span><span class="nt">ul</span><span class="p">&gt;</span>
        <span class="cp">{%</span> <span class="k">for</span> <span class="nv">city</span> <span class="k">in</span> <span class="nv">country.list</span> <span class="cp">%}</span>
          <span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;</span><span class="cp">{{</span> <span class="nv">city.name</span> <span class="cp">}}</span>: <span class="cp">{{</span> <span class="nv">city.population</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">li</span><span class="p">&gt;</span>
        <span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
    <span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span>
    <span class="p">&lt;/</span><span class="nt">li</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
<span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>Let’s walk through this example. <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">regroup</span> <span class="pre">%}</span></code> takes three arguments: the
list you want to regroup, the attribute to group by, and the name of the
resulting list. Here, we’re regrouping the <code class="docutils literal notranslate"><span class="pre">cities</span></code> list by the <code class="docutils literal notranslate"><span class="pre">country</span></code>
attribute and calling the result <code class="docutils literal notranslate"><span class="pre">country_list</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">regroup</span> <span class="pre">%}</span></code> produces a list (in this case, <code class="docutils literal notranslate"><span class="pre">country_list</span></code>) of
<strong>group objects</strong>. Group objects are instances of
<a class="reference external" href="https://docs.python.org/3/library/collections.html#collections.namedtuple" title="(in Python v3.14)"><code class="xref py py-func docutils literal notranslate"><span class="pre">namedtuple()</span></code></a> with two fields:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">grouper</span></code> – the item that was grouped by (e.g., the string “India” or
“Japan”).</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">list</span></code> – a list of all items in this group (e.g., a list of all cities
with country=’India’).</p></li>
</ul>
<p>Because <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">regroup</span> <span class="pre">%}</span></code> produces <a class="reference external" href="https://docs.python.org/3/library/collections.html#collections.namedtuple" title="(in Python v3.14)"><code class="xref py py-func docutils literal notranslate"><span class="pre">namedtuple()</span></code></a> objects,
you can also write the previous example as:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">regroup</span> <span class="nv">cities</span> <span class="nv">by</span> <span class="nv">country</span> <span class="k">as</span> <span class="nv">country_list</span> <span class="cp">%}</span>

<span class="p">&lt;</span><span class="nt">ul</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">for</span> <span class="nv">country</span><span class="o">,</span> <span class="nv">local_cities</span> <span class="k">in</span> <span class="nv">country_list</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;</span><span class="cp">{{</span> <span class="nv">country</span> <span class="cp">}}</span>
    <span class="p">&lt;</span><span class="nt">ul</span><span class="p">&gt;</span>
        <span class="cp">{%</span> <span class="k">for</span> <span class="nv">city</span> <span class="k">in</span> <span class="nv">local_cities</span> <span class="cp">%}</span>
          <span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;</span><span class="cp">{{</span> <span class="nv">city.name</span> <span class="cp">}}</span>: <span class="cp">{{</span> <span class="nv">city.population</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">li</span><span class="p">&gt;</span>
        <span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
    <span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span>
    <span class="p">&lt;/</span><span class="nt">li</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
<span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>Note that <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">regroup</span> <span class="pre">%}</span></code> does not order its input! Our example relies on the
fact that the <code class="docutils literal notranslate"><span class="pre">cities</span></code> list was ordered by <code class="docutils literal notranslate"><span class="pre">country</span></code> in the first place. If
the <code class="docutils literal notranslate"><span class="pre">cities</span></code> list did <em>not</em> order its members by <code class="docutils literal notranslate"><span class="pre">country</span></code>, the regrouping
would naively display more than one group for a single country. For example,
say the <code class="docutils literal notranslate"><span class="pre">cities</span></code> list was set to this (note that the countries are not
grouped together):</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">cities</span> <span class="o">=</span> <span class="p">[</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Mumbai&quot;</span><span class="p">,</span> <span class="s2">&quot;population&quot;</span><span class="p">:</span> <span class="s2">&quot;19,000,000&quot;</span><span class="p">,</span> <span class="s2">&quot;country&quot;</span><span class="p">:</span> <span class="s2">&quot;India&quot;</span><span class="p">},</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;New York&quot;</span><span class="p">,</span> <span class="s2">&quot;population&quot;</span><span class="p">:</span> <span class="s2">&quot;20,000,000&quot;</span><span class="p">,</span> <span class="s2">&quot;country&quot;</span><span class="p">:</span> <span class="s2">&quot;USA&quot;</span><span class="p">},</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Calcutta&quot;</span><span class="p">,</span> <span class="s2">&quot;population&quot;</span><span class="p">:</span> <span class="s2">&quot;15,000,000&quot;</span><span class="p">,</span> <span class="s2">&quot;country&quot;</span><span class="p">:</span> <span class="s2">&quot;India&quot;</span><span class="p">},</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Chicago&quot;</span><span class="p">,</span> <span class="s2">&quot;population&quot;</span><span class="p">:</span> <span class="s2">&quot;7,000,000&quot;</span><span class="p">,</span> <span class="s2">&quot;country&quot;</span><span class="p">:</span> <span class="s2">&quot;USA&quot;</span><span class="p">},</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Tokyo&quot;</span><span class="p">,</span> <span class="s2">&quot;population&quot;</span><span class="p">:</span> <span class="s2">&quot;33,000,000&quot;</span><span class="p">,</span> <span class="s2">&quot;country&quot;</span><span class="p">:</span> <span class="s2">&quot;Japan&quot;</span><span class="p">},</span>
<span class="p">]</span>
</pre></div>
</div>
<p>With this input for <code class="docutils literal notranslate"><span class="pre">cities</span></code>, the example <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">regroup</span> <span class="pre">%}</span></code> template code
above would result in the following output:</p>
<ul class="simple">
<li><p>India</p>
<ul>
<li><p>Mumbai: 19,000,000</p></li>
</ul>
</li>
<li><p>USA</p>
<ul>
<li><p>New York: 20,000,000</p></li>
</ul>
</li>
<li><p>India</p>
<ul>
<li><p>Calcutta: 15,000,000</p></li>
</ul>
</li>
<li><p>USA</p>
<ul>
<li><p>Chicago: 7,000,000</p></li>
</ul>
</li>
<li><p>Japan</p>
<ul>
<li><p>Tokyo: 33,000,000</p></li>
</ul>
</li>
</ul>
<p>The easiest solution to this gotcha is to make sure in your view code that the
data is ordered according to how you want to display it.</p>
<p>Another solution is to sort the data in the template using the
<a class="reference internal" href="#std-templatefilter-dictsort"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">dictsort</span></code></a> filter, if your data is in a list of dictionaries:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">regroup</span> <span class="nv">cities</span><span class="o">|</span><span class="nf">dictsort</span><span class="s2">:&quot;country&quot;</span> <span class="nv">by</span> <span class="nv">country</span> <span class="k">as</span> <span class="nv">country_list</span> <span class="cp">%}</span>
</pre></div>
</div>
<section id="s-grouping-on-other-properties">
<span id="grouping-on-other-properties"></span><h4>Grouping on other properties<a class="headerlink" href="#grouping-on-other-properties" title="Link to this heading">¶</a></h4>
<p>Any valid template lookup is a legal grouping attribute for the regroup
tag, including methods, attributes, dictionary keys and list items. For
example, if the “country” field is a foreign key to a class with
an attribute “description,” you could use:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">regroup</span> <span class="nv">cities</span> <span class="nv">by</span> <span class="nv">country.description</span> <span class="k">as</span> <span class="nv">country_list</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Or, if <code class="docutils literal notranslate"><span class="pre">country</span></code> is a field with <code class="docutils literal notranslate"><span class="pre">choices</span></code>, it will have a
<a class="reference internal" href="../models/instances.html#django.db.models.Model.get_FOO_display" title="django.db.models.Model.get_FOO_display"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_FOO_display()</span></code></a> method available as an
attribute, allowing  you to group on the display string rather than the
<code class="docutils literal notranslate"><span class="pre">choices</span></code> key:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">regroup</span> <span class="nv">cities</span> <span class="nv">by</span> <span class="nv">get_country_display</span> <span class="k">as</span> <span class="nv">country_list</span> <span class="cp">%}</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">country.grouper</span> <span class="pre">}}</span></code> will now display the value fields from the
<code class="docutils literal notranslate"><span class="pre">choices</span></code> set rather than the keys.</p>
</section>
</section>
<section id="s-resetcycle">
<span id="s-std-templatetag-resetcycle"></span><span id="resetcycle"></span><span id="std-templatetag-resetcycle"></span><h3><code class="docutils literal notranslate"><span class="pre">resetcycle</span></code><a class="headerlink" href="#resetcycle" title="Link to this heading">¶</a></h3>
<p>Resets a previous <a class="reference internal" href="#cycle">cycle</a> so that it restarts from its first item at its next
encounter. Without arguments, <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">resetcycle</span> <span class="pre">%}</span></code> will reset the last
<code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">cycle</span> <span class="pre">%}</span></code> defined in the template.</p>
<p>Example usage:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">for</span> <span class="nv">coach</span> <span class="k">in</span> <span class="nv">coach_list</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">h1</span><span class="p">&gt;</span><span class="cp">{{</span> <span class="nv">coach.name</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">h1</span><span class="p">&gt;</span>
    <span class="cp">{%</span> <span class="k">for</span> <span class="nv">athlete</span> <span class="k">in</span> <span class="nv">coach.athlete_set.all</span> <span class="cp">%}</span>
        <span class="p">&lt;</span><span class="nt">p</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">cycle</span> <span class="s1">&#39;odd&#39;</span> <span class="s1">&#39;even&#39;</span> <span class="cp">%}</span><span class="s">&quot;</span><span class="p">&gt;</span><span class="cp">{{</span> <span class="nv">athlete.name</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
    <span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
    <span class="cp">{%</span> <span class="k">resetcycle</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>This example would return this HTML:</p>
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">h1</span><span class="p">&gt;</span>Gareth<span class="p">&lt;/</span><span class="nt">h1</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">p</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;odd&quot;</span><span class="p">&gt;</span>Harry<span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">p</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;even&quot;</span><span class="p">&gt;</span>John<span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">p</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;odd&quot;</span><span class="p">&gt;</span>Nick<span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>

<span class="p">&lt;</span><span class="nt">h1</span><span class="p">&gt;</span>John<span class="p">&lt;/</span><span class="nt">h1</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">p</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;odd&quot;</span><span class="p">&gt;</span>Andrea<span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">p</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;even&quot;</span><span class="p">&gt;</span>Melissa<span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>Notice how the first block ends with <code class="docutils literal notranslate"><span class="pre">class=&quot;odd&quot;</span></code> and the new one starts
with <code class="docutils literal notranslate"><span class="pre">class=&quot;odd&quot;</span></code>. Without the <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">resetcycle</span> <span class="pre">%}</span></code> tag, the second block
would start with <code class="docutils literal notranslate"><span class="pre">class=&quot;even&quot;</span></code>.</p>
<p>You can also reset named cycle tags:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">for</span> <span class="nv">item</span> <span class="k">in</span> <span class="nv">list</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">p</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">cycle</span> <span class="s1">&#39;odd&#39;</span> <span class="s1">&#39;even&#39;</span> <span class="k">as</span> <span class="nv">stripe</span> <span class="cp">%}</span><span class="s"> </span><span class="cp">{%</span> <span class="k">cycle</span> <span class="s1">&#39;major&#39;</span> <span class="s1">&#39;minor&#39;</span> <span class="s1">&#39;minor&#39;</span> <span class="s1">&#39;minor&#39;</span> <span class="s1">&#39;minor&#39;</span> <span class="k">as</span> <span class="nv">tick</span> <span class="cp">%}</span><span class="s">&quot;</span><span class="p">&gt;</span>
        <span class="cp">{{</span> <span class="nv">item.data</span> <span class="cp">}}</span>
    <span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
    <span class="cp">{%</span> <span class="k">ifchanged</span> <span class="nv">item.category</span> <span class="cp">%}</span>
        <span class="p">&lt;</span><span class="nt">h1</span><span class="p">&gt;</span><span class="cp">{{</span> <span class="nv">item.category</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">h1</span><span class="p">&gt;</span>
        <span class="cp">{%</span> <span class="k">if</span> <span class="k">not</span> <span class="nb">forloop</span><span class="nv">.first</span> <span class="cp">%}{%</span> <span class="k">resetcycle</span> <span class="nv">tick</span> <span class="cp">%}{%</span> <span class="k">endif</span> <span class="cp">%}</span>
    <span class="cp">{%</span> <span class="k">endifchanged</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>In this example, we have both the alternating odd/even rows and a “major” row
every fifth row. Only the five-row cycle is reset when a category changes.</p>
</section>
<section id="s-spaceless">
<span id="s-std-templatetag-spaceless"></span><span id="spaceless"></span><span id="std-templatetag-spaceless"></span><h3><code class="docutils literal notranslate"><span class="pre">spaceless</span></code><a class="headerlink" href="#spaceless" title="Link to this heading">¶</a></h3>
<p>Removes whitespace between HTML tags. This includes tab
characters and newlines.</p>
<p>Example usage:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">spaceless</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>
        <span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;foo/&quot;</span><span class="p">&gt;</span>Foo<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
    <span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endspaceless</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>This example would return this HTML:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;foo/&quot;</span><span class="p">&gt;</span>Foo<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>Only space between <em>tags</em> is removed – not space between tags and text. In
this example, the space around <code class="docutils literal notranslate"><span class="pre">Hello</span></code> won’t be stripped:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">spaceless</span> <span class="cp">%}</span>
    <span class="p">&lt;</span><span class="nt">strong</span><span class="p">&gt;</span>
        Hello
    <span class="p">&lt;/</span><span class="nt">strong</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endspaceless</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-templatetag">
<span id="s-std-templatetag-templatetag"></span><span id="templatetag"></span><span id="std-templatetag-templatetag"></span><h3><code class="docutils literal notranslate"><span class="pre">templatetag</span></code><a class="headerlink" href="#templatetag" title="Link to this heading">¶</a></h3>
<p>Outputs one of the syntax characters used to compose template tags.</p>
<p>The template system has no concept of “escaping” individual characters.
However, you can use the <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">templatetag</span> <span class="pre">%}</span></code> tag to display one of the
template tag character combinations.</p>
<p>The argument tells which template bit to output:</p>
<table class="docutils">
<thead>
<tr class="row-odd"><th class="head"><p>Argument</p></th>
<th class="head"><p>Outputs</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">openblock</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{%</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">closeblock</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">%}</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">openvariable</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">closevariable</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">}}</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">openbrace</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">closebrace</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">}</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">opencomment</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{#</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">closecomment</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">#}</span></code></p></td>
</tr>
</tbody>
</table>
<p>Sample usage:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>The <span class="cp">{%</span> <span class="k">templatetag</span> <span class="nv">openblock</span> <span class="cp">%}</span> characters open a block.
</pre></div>
</div>
<p>See also the <a class="reference internal" href="#std-templatetag-verbatim"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">verbatim</span></code></a> tag for another way of including these
characters.</p>
</section>
<section id="s-url">
<span id="s-std-templatetag-url"></span><span id="url"></span><span id="std-templatetag-url"></span><h3><code class="docutils literal notranslate"><span class="pre">url</span></code><a class="headerlink" href="#url" title="Link to this heading">¶</a></h3>
<p>Returns an absolute path reference (a URL without the domain name) matching a
given view and optional parameters. Any special characters in the resulting
path will be encoded using <a class="reference internal" href="../utils.html#django.utils.encoding.iri_to_uri" title="django.utils.encoding.iri_to_uri"><code class="xref py py-func docutils literal notranslate"><span class="pre">iri_to_uri()</span></code></a>.</p>
<p>This is a way to output links without violating the DRY principle by having to
hardcode URLs in your templates:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">url</span> <span class="s1">&#39;some-url-name&#39;</span> <span class="nv">v1</span> <span class="nv">v2</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>The first argument is a <a class="reference internal" href="../../topics/http/urls.html#naming-url-patterns"><span class="std std-ref">URL pattern name</span></a>. It can
be a quoted literal or any other context variable. Additional arguments are
optional and should be space-separated values that will be used as arguments in
the URL. The example above shows passing positional arguments. Alternatively
you may use keyword syntax:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">url</span> <span class="s1">&#39;some-url-name&#39;</span> <span class="nv">arg1</span><span class="o">=</span><span class="nv">v1</span> <span class="nv">arg2</span><span class="o">=</span><span class="nv">v2</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Do not mix both positional and keyword syntax in a single call. All arguments
required by the URLconf should be present.</p>
<p>For example, suppose you have a view, <code class="docutils literal notranslate"><span class="pre">app_views.client</span></code>, whose URLconf
takes a client ID (here, <code class="docutils literal notranslate"><span class="pre">client()</span></code> is a method inside the views file
<code class="docutils literal notranslate"><span class="pre">app_views.py</span></code>). The URLconf line might look like this:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path</span><span class="p">(</span><span class="s2">&quot;client/&lt;int:id&gt;/&quot;</span><span class="p">,</span> <span class="n">app_views</span><span class="o">.</span><span class="n">client</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;app-views-client&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>If this app’s URLconf is included into the project’s URLconf under a path
such as this:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">path</span><span class="p">(</span><span class="s2">&quot;clients/&quot;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s2">&quot;project_name.app_name.urls&quot;</span><span class="p">))</span>
</pre></div>
</div>
<p>…then, in a template, you can create a link to this view like this:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">url</span> <span class="s1">&#39;app-views-client&#39;</span> <span class="nv">client.id</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>The template tag will output the string <code class="docutils literal notranslate"><span class="pre">/clients/client/123/</span></code>.</p>
<p>Note that if the URL you’re reversing doesn’t exist, you’ll get an
<a class="reference internal" href="../exceptions.html#django.urls.NoReverseMatch" title="django.urls.NoReverseMatch"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NoReverseMatch</span></code></a> exception raised, which will cause your
site to display an error page.</p>
<p>If you’d like to retrieve a URL without displaying it, you can use a slightly
different call:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">url</span> <span class="s1">&#39;some-url-name&#39;</span> <span class="nv">arg</span> <span class="nv">arg2</span> <span class="k">as</span> <span class="nv">the_url</span> <span class="cp">%}</span>

<span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">the_url</span> <span class="cp">}}</span><span class="s">&quot;</span><span class="p">&gt;</span>I&#39;m linking to <span class="cp">{{</span> <span class="nv">the_url</span> <span class="cp">}}</span><span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>The scope of the variable created by the  <code class="docutils literal notranslate"><span class="pre">as</span> <span class="pre">var</span></code> syntax is the
<code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">block</span> <span class="pre">%}</span></code> in which the <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">url</span> <span class="pre">%}</span></code> tag appears.</p>
<p>This <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">url</span> <span class="pre">...</span> <span class="pre">as</span> <span class="pre">var</span> <span class="pre">%}</span></code> syntax will <em>not</em> cause an error if the view is
missing. In practice you’ll use this to link to views that are optional:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">url</span> <span class="s1">&#39;some-url-name&#39;</span> <span class="k">as</span> <span class="nv">the_url</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">if</span> <span class="nv">the_url</span> <span class="cp">%}</span>
  <span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">the_url</span> <span class="cp">}}</span><span class="s">&quot;</span><span class="p">&gt;</span>Link to optional stuff<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>If you’d like to retrieve a namespaced URL, specify the fully qualified name:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">url</span> <span class="s1">&#39;myapp:view-name&#39;</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>This will follow the normal <a class="reference internal" href="../../topics/http/urls.html#topics-http-reversing-url-namespaces"><span class="std std-ref">namespaced URL resolution strategy</span></a>, including using any hints provided
by the context as to the current application.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Don’t forget to put quotes around the URL pattern <code class="docutils literal notranslate"><span class="pre">name</span></code>, otherwise the
value will be interpreted as a context variable!</p>
</div>
</section>
<section id="s-verbatim">
<span id="s-std-templatetag-verbatim"></span><span id="verbatim"></span><span id="std-templatetag-verbatim"></span><h3><code class="docutils literal notranslate"><span class="pre">verbatim</span></code><a class="headerlink" href="#verbatim" title="Link to this heading">¶</a></h3>
<p>Stops the template engine from rendering the contents of this block tag.</p>
<p>A common use is to allow a JavaScript template layer that collides with
Django’s syntax. For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">verbatim</span> <span class="cp">%}</span>
    <span class="cp">{{</span><span class="k">if</span> <span class="nv">dying</span><span class="cp">}}</span>Still alive.<span class="cp">{{</span><span class="o">/</span><span class="k">if</span><span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">endverbatim</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>You can also designate a specific closing tag, allowing the use of
<code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">endverbatim</span> <span class="pre">%}</span></code> as part of the unrendered contents:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">verbatim</span> <span class="nv">myblock</span> <span class="cp">%}</span>
    Avoid template rendering via the <span class="cp">{%</span> <span class="k">verbatim</span> <span class="cp">%}{%</span> <span class="k">endverbatim</span> <span class="cp">%}</span> block.
<span class="cp">{%</span> <span class="k">endverbatim</span> <span class="nv">myblock</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-widthratio">
<span id="s-std-templatetag-widthratio"></span><span id="widthratio"></span><span id="std-templatetag-widthratio"></span><h3><code class="docutils literal notranslate"><span class="pre">widthratio</span></code><a class="headerlink" href="#widthratio" title="Link to this heading">¶</a></h3>
<p>For creating bar charts and such, this tag calculates the ratio of a given
value to a maximum value, and then applies that ratio to a constant.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">img</span> <span class="na">src</span><span class="o">=</span><span class="s">&quot;bar.png&quot;</span> <span class="na">alt</span><span class="o">=</span><span class="s">&quot;Bar&quot;</span>
     <span class="na">height</span><span class="o">=</span><span class="s">&quot;10&quot;</span> <span class="na">width</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">widthratio</span> <span class="nv">this_value</span> <span class="nv">max_value</span> <span class="nv">max_width</span> <span class="cp">%}</span><span class="s">&quot;</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">this_value</span></code> is 175, <code class="docutils literal notranslate"><span class="pre">max_value</span></code> is 200, and <code class="docutils literal notranslate"><span class="pre">max_width</span></code> is 100, the
image in the above example will be 88 pixels wide
(because 175/200 = .875; .875 * 100 = 87.5 which is rounded up to 88).</p>
<p>In some cases you might want to capture the result of <code class="docutils literal notranslate"><span class="pre">widthratio</span></code> in a
variable. It can be useful, for instance, in a <a class="reference internal" href="../../topics/i18n/translation.html#std-templatetag-blocktranslate"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">blocktranslate</span></code></a> like
this:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">widthratio</span> <span class="nv">this_value</span> <span class="nv">max_value</span> <span class="nv">max_width</span> <span class="k">as</span> <span class="nv">width</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">blocktranslate</span> <span class="cp">%}</span>The width is: <span class="cp">{{</span> <span class="nv">width</span> <span class="cp">}}{%</span> <span class="k">endblocktranslate</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-with">
<span id="s-std-templatetag-with"></span><span id="with"></span><span id="std-templatetag-with"></span><h3><code class="docutils literal notranslate"><span class="pre">with</span></code><a class="headerlink" href="#with" title="Link to this heading">¶</a></h3>
<p>Caches a complex variable under a simpler name. This is useful when accessing
an “expensive” method (e.g., one that hits the database) multiple times.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">with</span> <span class="nv">total</span><span class="o">=</span><span class="nv">business.employees.count</span> <span class="cp">%}</span>
    <span class="cp">{{</span> <span class="nv">total</span> <span class="cp">}}</span> employee<span class="cp">{{</span> <span class="nv">total</span><span class="o">|</span><span class="nf">pluralize</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">endwith</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>The populated variable (in the example above, <code class="docutils literal notranslate"><span class="pre">total</span></code>) is only available
between the <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">with</span> <span class="pre">%}</span></code> and <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">endwith</span> <span class="pre">%}</span></code> tags.</p>
<p>You can assign more than one context variable:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">with</span> <span class="nv">alpha</span><span class="o">=</span><span class="m">1</span> <span class="nv">beta</span><span class="o">=</span><span class="m">2</span> <span class="cp">%}</span>
    ...
<span class="cp">{%</span> <span class="k">endwith</span> <span class="cp">%}</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The previous more verbose format is still supported:
<code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">with</span> <span class="pre">business.employees.count</span> <span class="pre">as</span> <span class="pre">total</span> <span class="pre">%}</span></code></p>
</div>
</section>
</section>
<section id="s-built-in-filter-reference">
<span id="s-ref-templates-builtins-filters"></span><span id="built-in-filter-reference"></span><span id="ref-templates-builtins-filters"></span><h2>Built-in filter reference<a class="headerlink" href="#built-in-filter-reference" title="Link to this heading">¶</a></h2>
<section id="s-add">
<span id="s-std-templatefilter-add"></span><span id="add"></span><span id="std-templatefilter-add"></span><h3><code class="docutils literal notranslate"><span class="pre">add</span></code><a class="headerlink" href="#add" title="Link to this heading">¶</a></h3>
<p>Adds the argument to the value.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">add</span><span class="s2">:&quot;2&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">4</span></code>, then the output will be <code class="docutils literal notranslate"><span class="pre">6</span></code>.</p>
<p>This filter will first try to coerce both values to integers. If this fails,
it’ll attempt to add the values together anyway. This will work on some data
types (strings, list, etc.) and fail on others. If it fails, the result will
be an empty string.</p>
<p>For example, if we have:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">first</span><span class="o">|</span><span class="nf">add</span><span class="o">:</span><span class="nv">second</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>and <code class="docutils literal notranslate"><span class="pre">first</span></code> is <code class="docutils literal notranslate"><span class="pre">[1,</span> <span class="pre">2,</span> <span class="pre">3]</span></code> and <code class="docutils literal notranslate"><span class="pre">second</span></code> is <code class="docutils literal notranslate"><span class="pre">[4,</span> <span class="pre">5,</span> <span class="pre">6]</span></code>, then the
output will be <code class="docutils literal notranslate"><span class="pre">[1,</span> <span class="pre">2,</span> <span class="pre">3,</span> <span class="pre">4,</span> <span class="pre">5,</span> <span class="pre">6]</span></code>.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Strings that can be coerced to integers will be <strong>summed</strong>, not
concatenated, as in the first example above.</p>
</div>
</section>
<section id="s-addslashes">
<span id="s-std-templatefilter-addslashes"></span><span id="addslashes"></span><span id="std-templatefilter-addslashes"></span><h3><code class="docutils literal notranslate"><span class="pre">addslashes</span></code><a class="headerlink" href="#addslashes" title="Link to this heading">¶</a></h3>
<p>Adds slashes before quotes. Useful for escaping strings in CSV, for example.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">addslashes</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;I'm</span> <span class="pre">using</span> <span class="pre">Django&quot;</span></code>, the output will be
<code class="docutils literal notranslate"><span class="pre">&quot;I\'m</span> <span class="pre">using</span> <span class="pre">Django&quot;</span></code>.</p>
</section>
<section id="s-capfirst">
<span id="s-std-templatefilter-capfirst"></span><span id="capfirst"></span><span id="std-templatefilter-capfirst"></span><h3><code class="docutils literal notranslate"><span class="pre">capfirst</span></code><a class="headerlink" href="#capfirst" title="Link to this heading">¶</a></h3>
<p>Capitalizes the first character of the value. If the first character is not
a letter, this filter has no effect.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">capfirst</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;django&quot;</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">&quot;Django&quot;</span></code>.</p>
</section>
<section id="s-center">
<span id="s-std-templatefilter-center"></span><span id="center"></span><span id="std-templatefilter-center"></span><h3><code class="docutils literal notranslate"><span class="pre">center</span></code><a class="headerlink" href="#center" title="Link to this heading">¶</a></h3>
<p>Centers the value in a field of a given width.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>&quot;<span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">center</span><span class="s2">:&quot;15&quot;</span> <span class="cp">}}</span>&quot;
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;Django&quot;</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">&quot;</span>&#160;&#160;&#160;&#160; <span class="pre">Django</span>&#160;&#160;&#160; <span class="pre">&quot;</span></code>.</p>
</section>
<section id="s-cut">
<span id="s-std-templatefilter-cut"></span><span id="cut"></span><span id="std-templatefilter-cut"></span><h3><code class="docutils literal notranslate"><span class="pre">cut</span></code><a class="headerlink" href="#cut" title="Link to this heading">¶</a></h3>
<p>Removes all values of arg from the given string.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">cut</span><span class="s2">:&quot; &quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;String</span> <span class="pre">with</span> <span class="pre">spaces&quot;</span></code>, the output will be
<code class="docutils literal notranslate"><span class="pre">&quot;Stringwithspaces&quot;</span></code>.</p>
</section>
<section id="s-date">
<span id="s-std-templatefilter-date"></span><span id="date"></span><span id="std-templatefilter-date"></span><h3><code class="docutils literal notranslate"><span class="pre">date</span></code><a class="headerlink" href="#date" title="Link to this heading">¶</a></h3>
<p>Formats a date according to the given format.</p>
<p>Uses a similar format to PHP’s <a class="reference external" href="https://www.php.net/manual/en/function.date.php">date()</a> function with some
differences.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>These format characters are not used in Django outside of templates. They
were designed to be compatible with PHP to ease transitioning for
designers.</p>
</div>
<p id="date-and-time-formatting-specifiers">Available format strings:</p>
<table class="docutils">
<thead>
<tr class="row-odd"><th class="head"><p>Format character</p></th>
<th class="head"><p>Description</p></th>
<th class="head"><p>Example output</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><strong>Day</strong></p></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">d</span></code></p></td>
<td><p>Day of the month, 2 digits with
leading zeros.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'01'</span></code> to <code class="docutils literal notranslate"><span class="pre">'31'</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">j</span></code></p></td>
<td><p>Day of the month without leading
zeros.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'1'</span></code> to <code class="docutils literal notranslate"><span class="pre">'31'</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">D</span></code></p></td>
<td><p>Day of the week, textual, 3 letters.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'Fri'</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">l</span></code></p></td>
<td><p>Day of the week, textual, long.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'Friday'</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">S</span></code></p></td>
<td><p>English ordinal suffix for day of the
month, 2 characters.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'st'</span></code>, <code class="docutils literal notranslate"><span class="pre">'nd'</span></code>, <code class="docutils literal notranslate"><span class="pre">'rd'</span></code> or <code class="docutils literal notranslate"><span class="pre">'th'</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">w</span></code></p></td>
<td><p>Day of the week, digits without
leading zeros.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'0'</span></code> (Sunday) to <code class="docutils literal notranslate"><span class="pre">'6'</span></code> (Saturday)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">z</span></code></p></td>
<td><p>Day of the year.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">1</span></code> to <code class="docutils literal notranslate"><span class="pre">366</span></code></p></td>
</tr>
<tr class="row-even"><td><p><strong>Week</strong></p></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">W</span></code></p></td>
<td><p>ISO-8601 week number of year, with
weeks starting on Monday.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">1</span></code>, <code class="docutils literal notranslate"><span class="pre">53</span></code></p></td>
</tr>
<tr class="row-even"><td><p><strong>Month</strong></p></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">m</span></code></p></td>
<td><p>Month, 2 digits with leading zeros.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'01'</span></code> to <code class="docutils literal notranslate"><span class="pre">'12'</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">n</span></code></p></td>
<td><p>Month without leading zeros.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'1'</span></code> to <code class="docutils literal notranslate"><span class="pre">'12'</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">M</span></code></p></td>
<td><p>Month, textual, 3 letters.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'Jan'</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">b</span></code></p></td>
<td><p>Month, textual, 3 letters, lowercase.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'jan'</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">E</span></code></p></td>
<td><p>Month, locale specific alternative
representation usually used for long
date representation.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'listopada'</span></code> (for Polish locale, as opposed to <code class="docutils literal notranslate"><span class="pre">'Listopad'</span></code>)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">F</span></code></p></td>
<td><p>Month, textual, long.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'January'</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">N</span></code></p></td>
<td><p>Month abbreviation in Associated Press
style. Proprietary extension.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'Jan.'</span></code>, <code class="docutils literal notranslate"><span class="pre">'Feb.'</span></code>, <code class="docutils literal notranslate"><span class="pre">'March'</span></code>, <code class="docutils literal notranslate"><span class="pre">'May'</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">t</span></code></p></td>
<td><p>Number of days in the given month.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">28</span></code> to <code class="docutils literal notranslate"><span class="pre">31</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><strong>Year</strong></p></td>
<td></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">y</span></code></p></td>
<td><p>Year, 2 digits with leading zeros.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'00'</span></code> to <code class="docutils literal notranslate"><span class="pre">'99'</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">Y</span></code></p></td>
<td><p>Year, 4 digits with leading zeros.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'0001'</span></code>, …, <code class="docutils literal notranslate"><span class="pre">'1999'</span></code>, …, <code class="docutils literal notranslate"><span class="pre">'9999'</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">L</span></code></p></td>
<td><p>Boolean for whether it’s a leap year.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">True</span></code> or <code class="docutils literal notranslate"><span class="pre">False</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">o</span></code></p></td>
<td><p>ISO-8601 week-numbering year,
corresponding to the ISO-8601 week
number (W) which uses leap weeks. See Y
for the more common year format.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'1999'</span></code></p></td>
</tr>
<tr class="row-even"><td><p><strong>Time</strong></p></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">g</span></code></p></td>
<td><p>Hour, 12-hour format without leading
zeros.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'1'</span></code> to <code class="docutils literal notranslate"><span class="pre">'12'</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">G</span></code></p></td>
<td><p>Hour, 24-hour format without leading
zeros.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'0'</span></code> to <code class="docutils literal notranslate"><span class="pre">'23'</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">h</span></code></p></td>
<td><p>Hour, 12-hour format.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'01'</span></code> to <code class="docutils literal notranslate"><span class="pre">'12'</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">H</span></code></p></td>
<td><p>Hour, 24-hour format.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'00'</span></code> to <code class="docutils literal notranslate"><span class="pre">'23'</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">i</span></code></p></td>
<td><p>Minutes.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'00'</span></code> to <code class="docutils literal notranslate"><span class="pre">'59'</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">s</span></code></p></td>
<td><p>Seconds, 2 digits with leading zeros.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'00'</span></code> to <code class="docutils literal notranslate"><span class="pre">'59'</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">u</span></code></p></td>
<td><p>Microseconds.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">000000</span></code> to <code class="docutils literal notranslate"><span class="pre">999999</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">a</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'a.m.'</span></code> or <code class="docutils literal notranslate"><span class="pre">'p.m.'</span></code> (Note that
this is slightly different than PHP’s
output, because this includes periods
to match Associated Press style.)</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'a.m.'</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">A</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'AM'</span></code> or <code class="docutils literal notranslate"><span class="pre">'PM'</span></code>.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'AM'</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">f</span></code></p></td>
<td><p>Time, in 12-hour hours and minutes,
with minutes left off if they’re zero.
Proprietary extension.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'1'</span></code>, <code class="docutils literal notranslate"><span class="pre">'1:30'</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">P</span></code></p></td>
<td><p>Time, in 12-hour hours, minutes and
‘a.m.’/’p.m.’, with minutes left off
if they’re zero and the special-case
strings ‘midnight’ and ‘noon’ if
appropriate. Proprietary extension.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'1</span> <span class="pre">a.m.'</span></code>, <code class="docutils literal notranslate"><span class="pre">'1:30</span> <span class="pre">p.m.'</span></code>, <code class="docutils literal notranslate"><span class="pre">'midnight'</span></code>, <code class="docutils literal notranslate"><span class="pre">'noon'</span></code>, <code class="docutils literal notranslate"><span class="pre">'12:30</span> <span class="pre">p.m.'</span></code></p></td>
</tr>
<tr class="row-even"><td><p><strong>Timezone</strong></p></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">e</span></code></p></td>
<td><p>Timezone name. Could be in any format,
or might return an empty string,
depending on the datetime.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">''</span></code>, <code class="docutils literal notranslate"><span class="pre">'GMT'</span></code>, <code class="docutils literal notranslate"><span class="pre">'-500'</span></code>, <code class="docutils literal notranslate"><span class="pre">'US/Eastern'</span></code>, etc.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">I</span></code></p></td>
<td><p>Daylight saving time, whether it’s in
effect or not.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'1'</span></code> or <code class="docutils literal notranslate"><span class="pre">'0'</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">O</span></code></p></td>
<td><p>Difference to Greenwich time in hours.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'+0200'</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">T</span></code></p></td>
<td><p>Time zone of this machine.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'EST'</span></code>, <code class="docutils literal notranslate"><span class="pre">'MDT'</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">Z</span></code></p></td>
<td><p>Time zone offset in seconds. The
offset for timezones west of UTC is
always negative, and for those east of
UTC is always positive.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">-43200</span></code> to <code class="docutils literal notranslate"><span class="pre">43200</span></code></p></td>
</tr>
<tr class="row-even"><td><p><strong>Date/Time</strong></p></td>
<td></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">c</span></code></p></td>
<td><p>ISO 8601 format. (Note: unlike other
formatters, such as “Z”, “O” or “r”,
the “c” formatter will not add timezone
offset if value is a naive datetime
(see <a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.tzinfo" title="(in Python v3.14)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.tzinfo</span></code></a>).</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">2008-01-02T10:30:00.000123+02:00</span></code>,
or <code class="docutils literal notranslate"><span class="pre">2008-01-02T10:30:00.000123</span></code> if the datetime is naive</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">r</span></code></p></td>
<td><p><span class="target" id="index-0"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc5322.html#section-3.3"><strong>RFC 5322</strong></a>
formatted date.</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">'Thu,</span> <span class="pre">21</span> <span class="pre">Dec</span> <span class="pre">2000</span> <span class="pre">16:01:07</span> <span class="pre">+0200'</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">U</span></code></p></td>
<td><p>Seconds since the Unix Epoch
(January 1 1970 00:00:00 UTC).</p></td>
<td></td>
</tr>
</tbody>
</table>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">date</span><span class="s2">:&quot;D d M Y&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is a <a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.datetime" title="(in Python v3.14)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> object (e.g., the result of
<code class="docutils literal notranslate"><span class="pre">datetime.datetime.now()</span></code>), the output will be the string
<code class="docutils literal notranslate"><span class="pre">'Wed</span> <span class="pre">09</span> <span class="pre">Jan</span> <span class="pre">2008'</span></code>.</p>
<p>The format passed can be one of the predefined ones <a class="reference internal" href="../settings.html#std-setting-DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATE_FORMAT</span></code></a>,
<a class="reference internal" href="../settings.html#std-setting-DATETIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATETIME_FORMAT</span></code></a>, <a class="reference internal" href="../settings.html#std-setting-SHORT_DATE_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SHORT_DATE_FORMAT</span></code></a> or
<a class="reference internal" href="../settings.html#std-setting-SHORT_DATETIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SHORT_DATETIME_FORMAT</span></code></a>, or a custom format that uses the format
specifiers shown in the table above. Note that predefined formats may vary
depending on the current locale.</p>
<p>Assuming that <a class="reference internal" href="../settings.html#std-setting-LANGUAGE_CODE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_CODE</span></code></a> is, for example, <code class="docutils literal notranslate"><span class="pre">&quot;es&quot;</span></code>, then for:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">date</span><span class="s2">:&quot;SHORT_DATE_FORMAT&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>the output would be the string <code class="docutils literal notranslate"><span class="pre">&quot;09/01/2008&quot;</span></code> (the <code class="docutils literal notranslate"><span class="pre">&quot;SHORT_DATE_FORMAT&quot;</span></code>
format specifier for the <code class="docutils literal notranslate"><span class="pre">es</span></code> locale as shipped with Django is <code class="docutils literal notranslate"><span class="pre">&quot;d/m/Y&quot;</span></code>).</p>
<p>When used without a format string, the <code class="docutils literal notranslate"><span class="pre">DATE_FORMAT</span></code> format specifier is
used. Assuming the same settings as the previous example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">date</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>outputs <code class="docutils literal notranslate"><span class="pre">9</span> <span class="pre">de</span> <span class="pre">Enero</span> <span class="pre">de</span> <span class="pre">2008</span></code> (the <code class="docutils literal notranslate"><span class="pre">DATE_FORMAT</span></code> format specifier for the
<code class="docutils literal notranslate"><span class="pre">es</span></code> locale is <code class="docutils literal notranslate"><span class="pre">r'j</span> <span class="pre">\d\e</span> <span class="pre">F</span> <span class="pre">\d\e</span> <span class="pre">Y'</span></code>). Both “d” and “e” are
backslash-escaped, because otherwise each is a format string that displays the
day and the timezone name, respectively.</p>
<p>You can combine <code class="docutils literal notranslate"><span class="pre">date</span></code> with the <a class="reference internal" href="#std-templatefilter-time"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">time</span></code></a> filter to render a full
representation of a <code class="docutils literal notranslate"><span class="pre">datetime</span></code> value. E.g.:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">date</span><span class="s2">:&quot;D d M Y&quot;</span> <span class="cp">}}</span> <span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">time</span><span class="s2">:&quot;H:i&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
</section>
<section id="s-default">
<span id="s-std-templatefilter-default"></span><span id="default"></span><span id="std-templatefilter-default"></span><h3><code class="docutils literal notranslate"><span class="pre">default</span></code><a class="headerlink" href="#default" title="Link to this heading">¶</a></h3>
<p>If value evaluates to <code class="docutils literal notranslate"><span class="pre">False</span></code>, uses the given default. Otherwise, uses the
value.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">default</span><span class="s2">:&quot;nothing&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;&quot;</span></code> (the empty string), the output will be <code class="docutils literal notranslate"><span class="pre">nothing</span></code>.</p>
</section>
<section id="s-default-if-none">
<span id="s-std-templatefilter-default_if_none"></span><span id="default-if-none"></span><span id="std-templatefilter-default_if_none"></span><h3><code class="docutils literal notranslate"><span class="pre">default_if_none</span></code><a class="headerlink" href="#default-if-none" title="Link to this heading">¶</a></h3>
<p>If (and only if) value is <code class="docutils literal notranslate"><span class="pre">None</span></code>, uses the given default. Otherwise, uses the
value.</p>
<p>Note that if an empty string is given, the default value will <em>not</em> be used.
Use the <a class="reference internal" href="#std-templatefilter-default"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">default</span></code></a> filter if you want to fallback for empty strings.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">default_if_none</span><span class="s2">:&quot;nothing&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">nothing</span></code>.</p>
</section>
<section id="s-dictsort">
<span id="s-std-templatefilter-dictsort"></span><span id="dictsort"></span><span id="std-templatefilter-dictsort"></span><h3><code class="docutils literal notranslate"><span class="pre">dictsort</span></code><a class="headerlink" href="#dictsort" title="Link to this heading">¶</a></h3>
<p>Takes a list of dictionaries and returns that list sorted by the key given in
the argument.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">dictsort</span><span class="s2">:&quot;name&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;zed&quot;</span><span class="p">,</span> <span class="s2">&quot;age&quot;</span><span class="p">:</span> <span class="mi">19</span><span class="p">},</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;amy&quot;</span><span class="p">,</span> <span class="s2">&quot;age&quot;</span><span class="p">:</span> <span class="mi">22</span><span class="p">},</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;joe&quot;</span><span class="p">,</span> <span class="s2">&quot;age&quot;</span><span class="p">:</span> <span class="mi">31</span><span class="p">},</span>
<span class="p">]</span>
</pre></div>
</div>
<p>then the output would be:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;amy&quot;</span><span class="p">,</span> <span class="s2">&quot;age&quot;</span><span class="p">:</span> <span class="mi">22</span><span class="p">},</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;joe&quot;</span><span class="p">,</span> <span class="s2">&quot;age&quot;</span><span class="p">:</span> <span class="mi">31</span><span class="p">},</span>
    <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;zed&quot;</span><span class="p">,</span> <span class="s2">&quot;age&quot;</span><span class="p">:</span> <span class="mi">19</span><span class="p">},</span>
<span class="p">]</span>
</pre></div>
</div>
<p>You can also do more complicated things like:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">for</span> <span class="nv">book</span> <span class="k">in</span> <span class="nv">books</span><span class="o">|</span><span class="nf">dictsort</span><span class="s2">:&quot;author.age&quot;</span> <span class="cp">%}</span>
    * <span class="cp">{{</span> <span class="nv">book.title</span> <span class="cp">}}</span> (<span class="cp">{{</span> <span class="nv">book.author.name</span> <span class="cp">}}</span>)
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">books</span></code> is:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
    <span class="p">{</span><span class="s2">&quot;title&quot;</span><span class="p">:</span> <span class="s2">&quot;1984&quot;</span><span class="p">,</span> <span class="s2">&quot;author&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;George&quot;</span><span class="p">,</span> <span class="s2">&quot;age&quot;</span><span class="p">:</span> <span class="mi">45</span><span class="p">}},</span>
    <span class="p">{</span><span class="s2">&quot;title&quot;</span><span class="p">:</span> <span class="s2">&quot;Timequake&quot;</span><span class="p">,</span> <span class="s2">&quot;author&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Kurt&quot;</span><span class="p">,</span> <span class="s2">&quot;age&quot;</span><span class="p">:</span> <span class="mi">75</span><span class="p">}},</span>
    <span class="p">{</span><span class="s2">&quot;title&quot;</span><span class="p">:</span> <span class="s2">&quot;Alice&quot;</span><span class="p">,</span> <span class="s2">&quot;author&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Lewis&quot;</span><span class="p">,</span> <span class="s2">&quot;age&quot;</span><span class="p">:</span> <span class="mi">33</span><span class="p">}},</span>
<span class="p">]</span>
</pre></div>
</div>
<p>then the output would be:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>* Alice (Lewis)
* 1984 (George)
* Timequake (Kurt)
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">dictsort</span></code> can also order a list of lists (or any other object implementing
<code class="docutils literal notranslate"><span class="pre">__getitem__()</span></code>) by elements at specified index. For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">dictsort</span><span class="o">:</span><span class="m">0</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
    <span class="p">(</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="s2">&quot;42&quot;</span><span class="p">),</span>
    <span class="p">(</span><span class="s2">&quot;c&quot;</span><span class="p">,</span> <span class="s2">&quot;string&quot;</span><span class="p">),</span>
    <span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="s2">&quot;foo&quot;</span><span class="p">),</span>
<span class="p">]</span>
</pre></div>
</div>
<p>then the output would be:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">[</span>
    <span class="p">(</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="s2">&quot;42&quot;</span><span class="p">),</span>
    <span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="s2">&quot;foo&quot;</span><span class="p">),</span>
    <span class="p">(</span><span class="s2">&quot;c&quot;</span><span class="p">,</span> <span class="s2">&quot;string&quot;</span><span class="p">),</span>
<span class="p">]</span>
</pre></div>
</div>
<p>You must pass the index as an integer rather than a string. The following
produce empty output:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">values</span><span class="o">|</span><span class="nf">dictsort</span><span class="s2">:&quot;0&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>Ordering by elements at specified index is not supported on dictionaries.</p>
</section>
<section id="s-dictsortreversed">
<span id="s-std-templatefilter-dictsortreversed"></span><span id="dictsortreversed"></span><span id="std-templatefilter-dictsortreversed"></span><h3><code class="docutils literal notranslate"><span class="pre">dictsortreversed</span></code><a class="headerlink" href="#dictsortreversed" title="Link to this heading">¶</a></h3>
<p>Takes a list of dictionaries and returns that list sorted in reverse order by
the key given in the argument. This works exactly the same as the above filter,
but the returned value will be in reverse order.</p>
</section>
<section id="s-divisibleby">
<span id="s-std-templatefilter-divisibleby"></span><span id="divisibleby"></span><span id="std-templatefilter-divisibleby"></span><h3><code class="docutils literal notranslate"><span class="pre">divisibleby</span></code><a class="headerlink" href="#divisibleby" title="Link to this heading">¶</a></h3>
<p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if the value is divisible by the argument.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">divisibleby</span><span class="s2">:&quot;3&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">21</span></code>, the output would be <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
</section>
<section id="s-escape">
<span id="s-std-templatefilter-escape"></span><span id="escape"></span><span id="std-templatefilter-escape"></span><h3><code class="docutils literal notranslate"><span class="pre">escape</span></code><a class="headerlink" href="#escape" title="Link to this heading">¶</a></h3>
<p>Escapes a string’s HTML. Specifically, it makes these replacements:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">&lt;</span></code> is converted to <code class="docutils literal notranslate"><span class="pre">&amp;lt;</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">&gt;</span></code> is converted to <code class="docutils literal notranslate"><span class="pre">&amp;gt;</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">'</span></code> (single quote) is converted to <code class="docutils literal notranslate"><span class="pre">&amp;#x27;</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">&quot;</span></code> (double quote) is converted to <code class="docutils literal notranslate"><span class="pre">&amp;quot;</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">&amp;</span></code> is converted to <code class="docutils literal notranslate"><span class="pre">&amp;amp;</span></code></p></li>
</ul>
<p>Applying <code class="docutils literal notranslate"><span class="pre">escape</span></code> to a variable that would normally have auto-escaping
applied to the result will only result in one round of escaping being done. So
it is safe to use this function even in auto-escaping environments. If you want
multiple escaping passes to be applied, use the <a class="reference internal" href="#std-templatefilter-force_escape"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">force_escape</span></code></a> filter.</p>
<p>For example, you can apply <code class="docutils literal notranslate"><span class="pre">escape</span></code> to fields when <a class="reference internal" href="#std-templatetag-autoescape"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">autoescape</span></code></a> is off:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">autoescape</span> <span class="nv">off</span> <span class="cp">%}</span>
    <span class="cp">{{</span> <span class="nv">title</span><span class="o">|</span><span class="nf">escape</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">endautoescape</span> <span class="cp">%}</span>
</pre></div>
</div>
<div class="admonition-chaining-escape-with-other-filters admonition">
<p class="admonition-title">Chaining <code class="docutils literal notranslate"><span class="pre">escape</span></code> with other filters</p>
<p>As mentioned in the <a class="reference internal" href="#std-templatetag-autoescape"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">autoescape</span></code></a> section, when filters including
<code class="docutils literal notranslate"><span class="pre">escape</span></code> are chained together, it can result in unexpected outcomes if
preceding filters mark a potentially unsafe string as safe due to the lack
of escaping caused by <a class="reference internal" href="#std-templatetag-autoescape"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">autoescape</span></code></a> being <code class="docutils literal notranslate"><span class="pre">off</span></code>.</p>
<p>In such cases, chaining <code class="docutils literal notranslate"><span class="pre">escape</span></code> would not reescape strings that have
already been marked as safe.</p>
<p>This is especially important when using filters that operate on sequences,
for example <a class="reference internal" href="#std-templatefilter-join"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">join</span></code></a>. If you need to escape each element in a
sequence, use the dedicated <a class="reference internal" href="#std-templatefilter-escapeseq"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">escapeseq</span></code></a> filter.</p>
</div>
</section>
<section id="s-escapejs">
<span id="s-std-templatefilter-escapejs"></span><span id="escapejs"></span><span id="std-templatefilter-escapejs"></span><h3><code class="docutils literal notranslate"><span class="pre">escapejs</span></code><a class="headerlink" href="#escapejs" title="Link to this heading">¶</a></h3>
<p>Escapes characters for use as a whole JavaScript string literal, within single
or double quotes, as below. This filter does not make the string safe for use
in <em>“JavaScript template literals”</em> (the JavaScript backtick syntax). Any other
uses not listed above are not supported. It is generally recommended that data
should be passed using HTML <code class="docutils literal notranslate"><span class="pre">data-</span></code> attributes, or the <a class="reference internal" href="#std-templatefilter-json_script"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">json_script</span></code></a>
filter, rather than in embedded JavaScript.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">script</span><span class="p">&gt;</span>
<span class="kd">let</span><span class="w"> </span><span class="nx">myValue</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">&#39;</span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">escapejs</span> <span class="cp">}}</span><span class="s1">&#39;</span>
</pre></div>
</div>
</section>
<section id="s-escapeseq">
<span id="s-std-templatefilter-escapeseq"></span><span id="escapeseq"></span><span id="std-templatefilter-escapeseq"></span><h3><code class="docutils literal notranslate"><span class="pre">escapeseq</span></code><a class="headerlink" href="#escapeseq" title="Link to this heading">¶</a></h3>
<p>Applies the <a class="reference internal" href="#std-templatefilter-escape"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">escape</span></code></a> filter to each element of a sequence. Useful in
conjunction with other filters that operate on sequences, such as
<a class="reference internal" href="#std-templatefilter-join"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">join</span></code></a>. For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">autoescape</span> <span class="nv">off</span> <span class="cp">%}</span>
    <span class="cp">{{</span> <span class="nv">my_list</span><span class="o">|</span><span class="nf">escapeseq</span><span class="o">|</span><span class="nf">join</span><span class="s2">:&quot;, &quot;</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">endautoescape</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-filesizeformat">
<span id="s-std-templatefilter-filesizeformat"></span><span id="filesizeformat"></span><span id="std-templatefilter-filesizeformat"></span><h3><code class="docutils literal notranslate"><span class="pre">filesizeformat</span></code><a class="headerlink" href="#filesizeformat" title="Link to this heading">¶</a></h3>
<p>Formats the value like a ‘human-readable’ file size (i.e. <code class="docutils literal notranslate"><span class="pre">'13</span> <span class="pre">KB'</span></code>,
<code class="docutils literal notranslate"><span class="pre">'4.1</span> <span class="pre">MB'</span></code>, <code class="docutils literal notranslate"><span class="pre">'102</span> <span class="pre">bytes'</span></code>, etc.).</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">filesizeformat</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is 123456789, the output would be <code class="docutils literal notranslate"><span class="pre">117.7</span> <span class="pre">MB</span></code>.</p>
<div class="admonition-file-sizes-and-si-units admonition">
<p class="admonition-title">File sizes and SI units</p>
<p>Strictly speaking, <code class="docutils literal notranslate"><span class="pre">filesizeformat</span></code> does not conform to the International
System of Units which recommends using KiB, MiB, GiB, etc. when byte sizes
are calculated in powers of 1024 (which is the case here). Instead, Django
uses traditional unit names (KB, MB, GB, etc.) corresponding to names that
are more commonly used.</p>
</div>
</section>
<section id="s-first">
<span id="s-std-templatefilter-first"></span><span id="first"></span><span id="std-templatefilter-first"></span><h3><code class="docutils literal notranslate"><span class="pre">first</span></code><a class="headerlink" href="#first" title="Link to this heading">¶</a></h3>
<p>Returns the first item in a list.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">first</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is the list <code class="docutils literal notranslate"><span class="pre">['a',</span> <span class="pre">'b',</span> <span class="pre">'c']</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">'a'</span></code>.</p>
</section>
<section id="s-floatformat">
<span id="s-std-templatefilter-floatformat"></span><span id="floatformat"></span><span id="std-templatefilter-floatformat"></span><h3><code class="docutils literal notranslate"><span class="pre">floatformat</span></code><a class="headerlink" href="#floatformat" title="Link to this heading">¶</a></h3>
<p>When used without an argument, rounds a floating-point number to one decimal
place – but only if there’s a decimal part to be displayed. For example:</p>
<table class="docutils">
<thead>
<tr class="row-odd"><th class="head"><p><code class="docutils literal notranslate"><span class="pre">value</span></code></p></th>
<th class="head"><p>Template</p></th>
<th class="head"><p>Output</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">34.23234</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34.2</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">34.00000</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">34.26000</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34.3</span></code></p></td>
</tr>
</tbody>
</table>
<p>If used with a numeric integer argument, <code class="docutils literal notranslate"><span class="pre">floatformat</span></code> rounds a number to
that many decimal places. For example:</p>
<table class="docutils">
<thead>
<tr class="row-odd"><th class="head"><p><code class="docutils literal notranslate"><span class="pre">value</span></code></p></th>
<th class="head"><p>Template</p></th>
<th class="head"><p>Output</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">34.23234</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat:3</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34.232</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">34.00000</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat:3</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34.000</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">34.26000</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat:3</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34.260</span></code></p></td>
</tr>
</tbody>
</table>
<p>Particularly useful is passing 0 (zero) as the argument which will round the
float to the nearest integer.</p>
<table class="docutils">
<thead>
<tr class="row-odd"><th class="head"><p><code class="docutils literal notranslate"><span class="pre">value</span></code></p></th>
<th class="head"><p>Template</p></th>
<th class="head"><p>Output</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">34.23234</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;0&quot;</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">34.00000</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;0&quot;</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">39.56000</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;0&quot;</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">40</span></code></p></td>
</tr>
</tbody>
</table>
<p>If the argument passed to <code class="docutils literal notranslate"><span class="pre">floatformat</span></code> is negative, it will round a number
to that many decimal places – but only if there’s a decimal part to be
displayed. For example:</p>
<table class="docutils">
<thead>
<tr class="row-odd"><th class="head"><p><code class="docutils literal notranslate"><span class="pre">value</span></code></p></th>
<th class="head"><p>Template</p></th>
<th class="head"><p>Output</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">34.23234</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;-3&quot;</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34.232</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">34.00000</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;-3&quot;</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">34.26000</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;-3&quot;</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34.260</span></code></p></td>
</tr>
</tbody>
</table>
<p>If the argument passed to <code class="docutils literal notranslate"><span class="pre">floatformat</span></code> has the <code class="docutils literal notranslate"><span class="pre">g</span></code> suffix, it will force
grouping by the <a class="reference internal" href="../settings.html#std-setting-THOUSAND_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">THOUSAND_SEPARATOR</span></code></a> for the active locale. For
example, when the active locale is <code class="docutils literal notranslate"><span class="pre">en</span></code> (English):</p>
<table class="docutils">
<thead>
<tr class="row-odd"><th class="head"><p><code class="docutils literal notranslate"><span class="pre">value</span></code></p></th>
<th class="head"><p>Template</p></th>
<th class="head"><p>Output</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">34232.34</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;2g&quot;</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34,232.34</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">34232.06</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;g&quot;</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34,232.1</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">34232.00</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;-3g&quot;</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34,232</span></code></p></td>
</tr>
</tbody>
</table>
<p>Output is always localized (independently of the <a class="reference internal" href="../../topics/i18n/formatting.html#std-templatetag-localize"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">{%</span> <span class="pre">localize</span> <span class="pre">off</span> <span class="pre">%}</span></code></a> tag) unless the argument passed to <code class="docutils literal notranslate"><span class="pre">floatformat</span></code> has the <code class="docutils literal notranslate"><span class="pre">u</span></code>
suffix, which will force disabling localization. For example, when the active
locale is <code class="docutils literal notranslate"><span class="pre">pl</span></code> (Polish):</p>
<table class="docutils">
<thead>
<tr class="row-odd"><th class="head"><p><code class="docutils literal notranslate"><span class="pre">value</span></code></p></th>
<th class="head"><p>Template</p></th>
<th class="head"><p>Output</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">34.23234</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;3&quot;</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34,232</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">34.23234</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;3u&quot;</span> <span class="pre">}}</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">34.232</span></code></p></td>
</tr>
</tbody>
</table>
<p>Using <code class="docutils literal notranslate"><span class="pre">floatformat</span></code> with no argument is equivalent to using <code class="docutils literal notranslate"><span class="pre">floatformat</span></code>
with an argument of <code class="docutils literal notranslate"><span class="pre">-1</span></code>.</p>
</section>
<section id="s-force-escape">
<span id="s-std-templatefilter-force_escape"></span><span id="force-escape"></span><span id="std-templatefilter-force_escape"></span><h3><code class="docutils literal notranslate"><span class="pre">force_escape</span></code><a class="headerlink" href="#force-escape" title="Link to this heading">¶</a></h3>
<p>Applies HTML escaping to a string (see the <a class="reference internal" href="#std-templatefilter-escape"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">escape</span></code></a> filter for
details). This filter is applied <em>immediately</em> and returns a new, escaped
string. This is useful in the rare cases where you need multiple escaping or
want to apply other filters to the escaped results. Normally, you want to use
the <a class="reference internal" href="#std-templatefilter-escape"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">escape</span></code></a> filter.</p>
<p>For example, if you want to catch the <code class="docutils literal notranslate"><span class="pre">&lt;p&gt;</span></code> HTML elements created by
the <a class="reference internal" href="#std-templatefilter-linebreaks"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">linebreaks</span></code></a> filter:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">autoescape</span> <span class="nv">off</span> <span class="cp">%}</span>
    <span class="cp">{{</span> <span class="nv">body</span><span class="o">|</span><span class="nf">linebreaks</span><span class="o">|</span><span class="nf">force_escape</span> <span class="cp">}}</span>
<span class="cp">{%</span> <span class="k">endautoescape</span> <span class="cp">%}</span>
</pre></div>
</div>
</section>
<section id="s-get-digit">
<span id="s-std-templatefilter-get_digit"></span><span id="get-digit"></span><span id="std-templatefilter-get_digit"></span><h3><code class="docutils literal notranslate"><span class="pre">get_digit</span></code><a class="headerlink" href="#get-digit" title="Link to this heading">¶</a></h3>
<p>Given a whole number, returns the requested digit, where 1 is the right-most
digit, 2 is the second-right-most digit, etc. Returns the original value for
invalid input (if input or argument is not an integer, or if argument is less
than 1). Otherwise, output is always an integer.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">get_digit</span><span class="s2">:&quot;2&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">123456789</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">8</span></code>.</p>
</section>
<section id="s-iriencode">
<span id="s-std-templatefilter-iriencode"></span><span id="iriencode"></span><span id="std-templatefilter-iriencode"></span><h3><code class="docutils literal notranslate"><span class="pre">iriencode</span></code><a class="headerlink" href="#iriencode" title="Link to this heading">¶</a></h3>
<p>Converts an IRI (Internationalized Resource Identifier) to a string that is
suitable for including in a URL. This is necessary if you’re trying to use
strings containing non-ASCII characters in a URL.</p>
<p>It’s safe to use this filter on a string that has already gone through the
<a class="reference internal" href="#std-templatefilter-urlencode"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">urlencode</span></code></a> filter.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">iriencode</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;?test=I</span> <span class="pre">♥</span> <span class="pre">Django&quot;</span></code>, the output will be
<code class="docutils literal notranslate"><span class="pre">&quot;?test=I%20%E2%99%A5%20Django&quot;</span></code>.</p>
</section>
<section id="s-join">
<span id="s-std-templatefilter-join"></span><span id="join"></span><span id="std-templatefilter-join"></span><h3><code class="docutils literal notranslate"><span class="pre">join</span></code><a class="headerlink" href="#join" title="Link to this heading">¶</a></h3>
<p>Joins a list with a string, like Python’s <code class="docutils literal notranslate"><span class="pre">str.join(list)</span></code></p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">join</span><span class="s2">:&quot; // &quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is the list <code class="docutils literal notranslate"><span class="pre">['a',</span> <span class="pre">'b',</span> <span class="pre">'c']</span></code>, the output will be the string
<code class="docutils literal notranslate"><span class="pre">&quot;a</span> <span class="pre">//</span> <span class="pre">b</span> <span class="pre">//</span> <span class="pre">c&quot;</span></code>.</p>
</section>
<section id="s-json-script">
<span id="s-std-templatefilter-json_script"></span><span id="json-script"></span><span id="std-templatefilter-json_script"></span><h3><code class="docutils literal notranslate"><span class="pre">json_script</span></code><a class="headerlink" href="#json-script" title="Link to this heading">¶</a></h3>
<p>Safely outputs a Python object as JSON, wrapped in a <code class="docutils literal notranslate"><span class="pre">&lt;script&gt;</span></code> tag, ready
for use with JavaScript.</p>
<p><strong>Argument:</strong> The optional HTML “id” of the <code class="docutils literal notranslate"><span class="pre">&lt;script&gt;</span></code> tag.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">json_script</span><span class="s2">:&quot;hello-data&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is the dictionary <code class="docutils literal notranslate"><span class="pre">{'hello':</span> <span class="pre">'world'}</span></code>, the output will be:</p>
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">script</span> <span class="na">id</span><span class="o">=</span><span class="s">&quot;hello-data&quot;</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;application/json&quot;</span><span class="p">&gt;{</span><span class="s2">&quot;hello&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;world&quot;</span><span class="p">}&lt;/</span><span class="nt">script</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>The resulting data can be accessed in JavaScript like this:</p>
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">const</span><span class="w"> </span><span class="nx">value</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="s1">&#39;hello-data&#39;</span><span class="p">).</span><span class="nx">textContent</span><span class="p">);</span>
</pre></div>
</div>
<p>XSS attacks are mitigated by escaping the characters “&lt;”, “&gt;” and “&amp;”. For
example if <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">{'hello':</span> <span class="pre">'world&lt;/script&gt;&amp;amp;'}</span></code>, the output is:</p>
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">script</span> <span class="na">id</span><span class="o">=</span><span class="s">&quot;hello-data&quot;</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;application/json&quot;</span><span class="p">&gt;{</span><span class="s2">&quot;hello&quot;</span><span class="o">:</span><span class="w"> </span><span class="s2">&quot;world\\u003C/script\\u003E\\u0026amp;&quot;</span><span class="p">}&lt;/</span><span class="nt">script</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>This is compatible with a strict Content Security Policy that prohibits in-page
script execution. It also maintains a clean separation between passive data and
executable code.</p>
</section>
<section id="s-last">
<span id="s-std-templatefilter-last"></span><span id="last"></span><span id="std-templatefilter-last"></span><h3><code class="docutils literal notranslate"><span class="pre">last</span></code><a class="headerlink" href="#last" title="Link to this heading">¶</a></h3>
<p>Returns the last item in a list.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">last</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is the list <code class="docutils literal notranslate"><span class="pre">['a',</span> <span class="pre">'b',</span> <span class="pre">'c',</span> <span class="pre">'d']</span></code>, the output will be the
string <code class="docutils literal notranslate"><span class="pre">&quot;d&quot;</span></code>.</p>
</section>
<section id="s-length">
<span id="s-std-templatefilter-length"></span><span id="length"></span><span id="std-templatefilter-length"></span><h3><code class="docutils literal notranslate"><span class="pre">length</span></code><a class="headerlink" href="#length" title="Link to this heading">¶</a></h3>
<p>Returns the length of the value. This works for both strings and lists.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">length</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">['a',</span> <span class="pre">'b',</span> <span class="pre">'c',</span> <span class="pre">'d']</span></code> or <code class="docutils literal notranslate"><span class="pre">&quot;abcd&quot;</span></code>, the output will be
<code class="docutils literal notranslate"><span class="pre">4</span></code>.</p>
<p>The filter returns <code class="docutils literal notranslate"><span class="pre">0</span></code> for an undefined variable.</p>
</section>
<section id="s-linebreaks">
<span id="s-std-templatefilter-linebreaks"></span><span id="linebreaks"></span><span id="std-templatefilter-linebreaks"></span><h3><code class="docutils literal notranslate"><span class="pre">linebreaks</span></code><a class="headerlink" href="#linebreaks" title="Link to this heading">¶</a></h3>
<p>Replaces line breaks in plain text with appropriate HTML; a single
newline becomes an HTML line break (<code class="docutils literal notranslate"><span class="pre">&lt;br&gt;</span></code>) and a new line
followed by a blank line becomes a paragraph break (<code class="docutils literal notranslate"><span class="pre">&lt;/p&gt;</span></code>).</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">linebreaks</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">Joel\nis</span> <span class="pre">a</span> <span class="pre">slug</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">&lt;p&gt;Joel&lt;br&gt;is</span> <span class="pre">a</span>
<span class="pre">slug&lt;/p&gt;</span></code>.</p>
</section>
<section id="s-linebreaksbr">
<span id="s-std-templatefilter-linebreaksbr"></span><span id="linebreaksbr"></span><span id="std-templatefilter-linebreaksbr"></span><h3><code class="docutils literal notranslate"><span class="pre">linebreaksbr</span></code><a class="headerlink" href="#linebreaksbr" title="Link to this heading">¶</a></h3>
<p>Converts all newlines in a piece of plain text to HTML line breaks
(<code class="docutils literal notranslate"><span class="pre">&lt;br&gt;</span></code>).</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">linebreaksbr</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">Joel\nis</span> <span class="pre">a</span> <span class="pre">slug</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">Joel&lt;br&gt;is</span> <span class="pre">a</span>
<span class="pre">slug</span></code>.</p>
</section>
<section id="s-linenumbers">
<span id="s-std-templatefilter-linenumbers"></span><span id="linenumbers"></span><span id="std-templatefilter-linenumbers"></span><h3><code class="docutils literal notranslate"><span class="pre">linenumbers</span></code><a class="headerlink" href="#linenumbers" title="Link to this heading">¶</a></h3>
<p>Displays text with line numbers.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">linenumbers</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>one
two
three
</pre></div>
</div>
<p>the output will be:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>1. one
2. two
3. three
</pre></div>
</div>
</section>
<section id="s-ljust">
<span id="s-std-templatefilter-ljust"></span><span id="ljust"></span><span id="std-templatefilter-ljust"></span><h3><code class="docutils literal notranslate"><span class="pre">ljust</span></code><a class="headerlink" href="#ljust" title="Link to this heading">¶</a></h3>
<p>Left-aligns the value in a field of a given width.</p>
<p><strong>Argument:</strong> field size</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>&quot;<span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">ljust</span><span class="s2">:&quot;10&quot;</span> <span class="cp">}}</span>&quot;
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">Django</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">&quot;Django</span>&#160;&#160;&#160; <span class="pre">&quot;</span></code>.</p>
</section>
<section id="s-lower">
<span id="s-std-templatefilter-lower"></span><span id="lower"></span><span id="std-templatefilter-lower"></span><h3><code class="docutils literal notranslate"><span class="pre">lower</span></code><a class="headerlink" href="#lower" title="Link to this heading">¶</a></h3>
<p>Converts a string into all lowercase.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">lower</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">Totally</span> <span class="pre">LOVING</span> <span class="pre">this</span> <span class="pre">Album!</span></code>, the output will be
<code class="docutils literal notranslate"><span class="pre">totally</span> <span class="pre">loving</span> <span class="pre">this</span> <span class="pre">album!</span></code>.</p>
</section>
<section id="s-make-list">
<span id="s-std-templatefilter-make_list"></span><span id="make-list"></span><span id="std-templatefilter-make_list"></span><h3><code class="docutils literal notranslate"><span class="pre">make_list</span></code><a class="headerlink" href="#make-list" title="Link to this heading">¶</a></h3>
<p>Returns the value turned into a list. For a string, it’s a list of characters.
For an integer, the argument is cast to a string before creating a list.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">make_list</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is the string <code class="docutils literal notranslate"><span class="pre">&quot;Joel&quot;</span></code>, the output would be the list
<code class="docutils literal notranslate"><span class="pre">['J',</span> <span class="pre">'o',</span> <span class="pre">'e',</span> <span class="pre">'l']</span></code>. If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">123</span></code>, the output will be the
list <code class="docutils literal notranslate"><span class="pre">['1',</span> <span class="pre">'2',</span> <span class="pre">'3']</span></code>.</p>
</section>
<section id="s-phone2numeric">
<span id="s-std-templatefilter-phone2numeric"></span><span id="phone2numeric"></span><span id="std-templatefilter-phone2numeric"></span><h3><code class="docutils literal notranslate"><span class="pre">phone2numeric</span></code><a class="headerlink" href="#phone2numeric" title="Link to this heading">¶</a></h3>
<p>Converts a phone number (possibly containing letters) to its numerical
equivalent.</p>
<p>The input doesn’t have to be a valid phone number. This will happily convert
any string.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">phone2numeric</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">800-COLLECT</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">800-2655328</span></code>.</p>
</section>
<section id="s-pluralize">
<span id="s-std-templatefilter-pluralize"></span><span id="pluralize"></span><span id="std-templatefilter-pluralize"></span><h3><code class="docutils literal notranslate"><span class="pre">pluralize</span></code><a class="headerlink" href="#pluralize" title="Link to this heading">¶</a></h3>
<p>Returns a plural suffix if the value is not <code class="docutils literal notranslate"><span class="pre">1</span></code>, <code class="docutils literal notranslate"><span class="pre">'1'</span></code>, or an object of
length 1. By default, this suffix is <code class="docutils literal notranslate"><span class="pre">'s'</span></code>.</p>
<p>Example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>You have <span class="cp">{{</span> <span class="nv">num_messages</span> <span class="cp">}}</span> message<span class="cp">{{</span> <span class="nv">num_messages</span><span class="o">|</span><span class="nf">pluralize</span> <span class="cp">}}</span>.
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">num_messages</span></code> is <code class="docutils literal notranslate"><span class="pre">1</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">You</span> <span class="pre">have</span> <span class="pre">1</span> <span class="pre">message.</span></code>
If <code class="docutils literal notranslate"><span class="pre">num_messages</span></code> is <code class="docutils literal notranslate"><span class="pre">2</span></code>  the output will be <code class="docutils literal notranslate"><span class="pre">You</span> <span class="pre">have</span> <span class="pre">2</span> <span class="pre">messages.</span></code></p>
<p>For words that require a suffix other than <code class="docutils literal notranslate"><span class="pre">'s'</span></code>, you can provide an
alternate suffix as a parameter to the filter.</p>
<p>Example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>You have <span class="cp">{{</span> <span class="nv">num_walruses</span> <span class="cp">}}</span> walrus<span class="cp">{{</span> <span class="nv">num_walruses</span><span class="o">|</span><span class="nf">pluralize</span><span class="s2">:&quot;es&quot;</span> <span class="cp">}}</span>.
</pre></div>
</div>
<p>For words that don’t pluralize by simple suffix, you can specify both a
singular and plural suffix, separated by a comma.</p>
<p>Example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>You have <span class="cp">{{</span> <span class="nv">num_cherries</span> <span class="cp">}}</span> cherr<span class="cp">{{</span> <span class="nv">num_cherries</span><span class="o">|</span><span class="nf">pluralize</span><span class="s2">:&quot;y,ies&quot;</span> <span class="cp">}}</span>.
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Use <a class="reference internal" href="../../topics/i18n/translation.html#std-templatetag-blocktranslate"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">blocktranslate</span></code></a> to pluralize translated strings.</p>
</div>
</section>
<section id="s-pprint">
<span id="s-std-templatefilter-pprint"></span><span id="pprint"></span><span id="std-templatefilter-pprint"></span><h3><code class="docutils literal notranslate"><span class="pre">pprint</span></code><a class="headerlink" href="#pprint" title="Link to this heading">¶</a></h3>
<p>A wrapper around <a class="reference external" href="https://docs.python.org/3/library/pprint.html#pprint.pprint" title="(in Python v3.14)"><code class="xref py py-func docutils literal notranslate"><span class="pre">pprint.pprint()</span></code></a> – for debugging, really.</p>
</section>
<section id="s-random">
<span id="s-std-templatefilter-random"></span><span id="random"></span><span id="std-templatefilter-random"></span><h3><code class="docutils literal notranslate"><span class="pre">random</span></code><a class="headerlink" href="#random" title="Link to this heading">¶</a></h3>
<p>Returns a random item from the given list.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">random</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is the list <code class="docutils literal notranslate"><span class="pre">['a',</span> <span class="pre">'b',</span> <span class="pre">'c',</span> <span class="pre">'d']</span></code>, the output could be <code class="docutils literal notranslate"><span class="pre">&quot;b&quot;</span></code>.</p>
</section>
<section id="s-rjust">
<span id="s-std-templatefilter-rjust"></span><span id="rjust"></span><span id="std-templatefilter-rjust"></span><h3><code class="docutils literal notranslate"><span class="pre">rjust</span></code><a class="headerlink" href="#rjust" title="Link to this heading">¶</a></h3>
<p>Right-aligns the value in a field of a given width.</p>
<p><strong>Argument:</strong> field size</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>&quot;<span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">rjust</span><span class="s2">:&quot;10&quot;</span> <span class="cp">}}</span>&quot;
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">Django</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">&quot;</span>&#160;&#160;&#160; <span class="pre">Django&quot;</span></code>.</p>
</section>
<section id="s-safe">
<span id="s-std-templatefilter-safe"></span><span id="safe"></span><span id="std-templatefilter-safe"></span><h3><code class="docutils literal notranslate"><span class="pre">safe</span></code><a class="headerlink" href="#safe" title="Link to this heading">¶</a></h3>
<p>Marks a string as not requiring further HTML escaping prior to output. When
autoescaping is off, this filter has no effect.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If you are chaining filters, a filter applied after <code class="docutils literal notranslate"><span class="pre">safe</span></code> can
make the contents unsafe again. For example, the following code
prints the variable as is, unescaped:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">var</span><span class="o">|</span><span class="nf">safe</span><span class="o">|</span><span class="nf">escape</span> <span class="cp">}}</span>
</pre></div>
</div>
</div>
</section>
<section id="s-safeseq">
<span id="s-std-templatefilter-safeseq"></span><span id="safeseq"></span><span id="std-templatefilter-safeseq"></span><h3><code class="docutils literal notranslate"><span class="pre">safeseq</span></code><a class="headerlink" href="#safeseq" title="Link to this heading">¶</a></h3>
<p>Applies the <a class="reference internal" href="#std-templatefilter-safe"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">safe</span></code></a> filter to each element of a sequence. Useful in
conjunction with other filters that operate on sequences, such as
<a class="reference internal" href="#std-templatefilter-join"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">join</span></code></a>. For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">some_list</span><span class="o">|</span><span class="nf">safeseq</span><span class="o">|</span><span class="nf">join</span><span class="s2">:&quot;, &quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>You couldn’t use the <a class="reference internal" href="#std-templatefilter-safe"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">safe</span></code></a> filter directly in this case, as it would
first convert the variable into a string, rather than working with the
individual elements of the sequence.</p>
</section>
<section id="s-slice">
<span id="s-std-templatefilter-slice"></span><span id="slice"></span><span id="std-templatefilter-slice"></span><h3><code class="docutils literal notranslate"><span class="pre">slice</span></code><a class="headerlink" href="#slice" title="Link to this heading">¶</a></h3>
<p>Returns a slice of the list.</p>
<p>Uses the same syntax as Python’s list slicing. See the <a class="reference external" href="https://docs.python.org/3/tutorial/introduction.html#lists">Python documentation</a> for an
introduction.</p>
<p>Example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">some_list</span><span class="o">|</span><span class="nf">slice</span><span class="s2">:&quot;:2&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">some_list</span></code> is <code class="docutils literal notranslate"><span class="pre">['a',</span> <span class="pre">'b',</span> <span class="pre">'c']</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">['a',</span> <span class="pre">'b']</span></code>.</p>
</section>
<section id="s-slugify">
<span id="s-std-templatefilter-slugify"></span><span id="slugify"></span><span id="std-templatefilter-slugify"></span><h3><code class="docutils literal notranslate"><span class="pre">slugify</span></code><a class="headerlink" href="#slugify" title="Link to this heading">¶</a></h3>
<p>Converts to ASCII. Converts spaces to hyphens. Removes characters that aren’t
alphanumerics, underscores, or hyphens. Converts to lowercase. Also strips
leading and trailing whitespace.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">slugify</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug&quot;</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">&quot;joel-is-a-slug&quot;</span></code>.</p>
</section>
<section id="s-stringformat">
<span id="s-std-templatefilter-stringformat"></span><span id="stringformat"></span><span id="std-templatefilter-stringformat"></span><h3><code class="docutils literal notranslate"><span class="pre">stringformat</span></code><a class="headerlink" href="#stringformat" title="Link to this heading">¶</a></h3>
<p>Formats the variable according to the argument, a string formatting specifier.
This specifier uses the <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#old-string-formatting" title="(in Python v3.14)"><span>printf-style String Formatting</span></a> syntax, with the exception
that the leading “%” is dropped.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">stringformat</span><span class="s2">:&quot;E&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">10</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">1.000000E+01</span></code>.</p>
</section>
<section id="s-striptags">
<span id="s-std-templatefilter-striptags"></span><span id="striptags"></span><span id="std-templatefilter-striptags"></span><h3><code class="docutils literal notranslate"><span class="pre">striptags</span></code><a class="headerlink" href="#striptags" title="Link to this heading">¶</a></h3>
<p>Makes all possible efforts to strip all [X]HTML tags.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">striptags</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;&lt;b&gt;Joel&lt;/b&gt;</span> <span class="pre">&lt;button&gt;is&lt;/button&gt;</span> <span class="pre">a</span> <span class="pre">&lt;span&gt;slug&lt;/span&gt;&quot;</span></code>, the
output will be <code class="docutils literal notranslate"><span class="pre">&quot;Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug&quot;</span></code>.</p>
<div class="admonition-no-safety-guarantee admonition">
<p class="admonition-title">No safety guarantee</p>
<p>Note that <code class="docutils literal notranslate"><span class="pre">striptags</span></code> doesn’t give any guarantee about its output being
HTML safe, particularly with non valid HTML input. So <strong>NEVER</strong> apply the
<code class="docutils literal notranslate"><span class="pre">safe</span></code> filter to a <code class="docutils literal notranslate"><span class="pre">striptags</span></code> output. If you are looking for something
more robust, consider using a third-party HTML sanitizing tool.</p>
</div>
</section>
<section id="s-time">
<span id="s-std-templatefilter-time"></span><span id="time"></span><span id="std-templatefilter-time"></span><h3><code class="docutils literal notranslate"><span class="pre">time</span></code><a class="headerlink" href="#time" title="Link to this heading">¶</a></h3>
<p>Formats a time according to the given format.</p>
<p>Given format can be the predefined one <a class="reference internal" href="../settings.html#std-setting-TIME_FORMAT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_FORMAT</span></code></a>, or a custom
format, same as the <a class="reference internal" href="#std-templatefilter-date"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">date</span></code></a> filter. Note that the predefined format
is locale-dependent.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">time</span><span class="s2">:&quot;H:i&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">datetime.datetime.now()</span></code>, the output will be
the string <code class="docutils literal notranslate"><span class="pre">&quot;01:23&quot;</span></code>.</p>
<p>Note that you can backslash-escape a format string if you want to use the
“raw” value. In this example, both “h” and “m” are backslash-escaped, because
otherwise each is a format string that displays the hour and the month,
respectively:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">time</span><span class="s2">:&quot;H\h i\m&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>This would display as “01h 23m”.</p>
<p>Another example:</p>
<p>Assuming that <a class="reference internal" href="../settings.html#std-setting-LANGUAGE_CODE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_CODE</span></code></a> is, for example, <code class="docutils literal notranslate"><span class="pre">&quot;de&quot;</span></code>, then for:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">time</span><span class="s2">:&quot;TIME_FORMAT&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>the output will be the string <code class="docutils literal notranslate"><span class="pre">&quot;01:23&quot;</span></code> (The <code class="docutils literal notranslate"><span class="pre">&quot;TIME_FORMAT&quot;</span></code> format
specifier for the <code class="docutils literal notranslate"><span class="pre">de</span></code> locale as shipped with Django is <code class="docutils literal notranslate"><span class="pre">&quot;H:i&quot;</span></code>).</p>
<p>The <code class="docutils literal notranslate"><span class="pre">time</span></code> filter will only accept parameters in the format string that
relate to the time of day, not the date. If you need to format a <code class="docutils literal notranslate"><span class="pre">date</span></code>
value, use the <a class="reference internal" href="#std-templatefilter-date"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">date</span></code></a> filter instead (or along with <a class="reference internal" href="#std-templatefilter-time"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">time</span></code></a> if
you need to render a full <a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.datetime" title="(in Python v3.14)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> value).</p>
<p>There is one exception the above rule: When passed a <code class="docutils literal notranslate"><span class="pre">datetime</span></code> value with
attached timezone information (a <a class="reference internal" href="../../topics/i18n/timezones.html#naive-vs-aware-datetimes"><span class="std std-ref">time-zone-aware</span></a> <code class="docutils literal notranslate"><span class="pre">datetime</span></code> instance) the <code class="docutils literal notranslate"><span class="pre">time</span></code> filter will
accept the timezone-related <a class="reference internal" href="#date-and-time-formatting-specifiers"><span class="std std-ref">format specifiers</span></a> <code class="docutils literal notranslate"><span class="pre">'e'</span></code>, <code class="docutils literal notranslate"><span class="pre">'O'</span></code> , <code class="docutils literal notranslate"><span class="pre">'T'</span></code> and <code class="docutils literal notranslate"><span class="pre">'Z'</span></code>.</p>
<p>When used without a format string, the <code class="docutils literal notranslate"><span class="pre">TIME_FORMAT</span></code> format specifier is
used:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">time</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>is the same as:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">time</span><span class="s2">:&quot;TIME_FORMAT&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
</section>
<section id="s-timesince">
<span id="s-std-templatefilter-timesince"></span><span id="timesince"></span><span id="std-templatefilter-timesince"></span><h3><code class="docutils literal notranslate"><span class="pre">timesince</span></code><a class="headerlink" href="#timesince" title="Link to this heading">¶</a></h3>
<p>Formats a date as the time since that date (e.g., “4 days, 6 hours”).</p>
<p>Takes an optional argument that is a variable containing the date to use as
the comparison point (without the argument, the comparison point is <em>now</em>).
For example, if <code class="docutils literal notranslate"><span class="pre">blog_date</span></code> is a date instance representing midnight on 1
June 2006, and <code class="docutils literal notranslate"><span class="pre">comment_date</span></code> is a date instance for 08:00 on 1 June 2006,
then the following would return “8 hours”:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">blog_date</span><span class="o">|</span><span class="nf">timesince</span><span class="o">:</span><span class="nv">comment_date</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>Comparing offset-naive and offset-aware datetimes will return an empty string.</p>
<p>Minutes is the smallest unit used, and “0 minutes” will be returned for any
date that is in the future relative to the comparison point.</p>
</section>
<section id="s-timeuntil">
<span id="s-std-templatefilter-timeuntil"></span><span id="timeuntil"></span><span id="std-templatefilter-timeuntil"></span><h3><code class="docutils literal notranslate"><span class="pre">timeuntil</span></code><a class="headerlink" href="#timeuntil" title="Link to this heading">¶</a></h3>
<p>Similar to <code class="docutils literal notranslate"><span class="pre">timesince</span></code>, except that it measures the time from now until the
given date or datetime. For example, if today is 1 June 2006 and
<code class="docutils literal notranslate"><span class="pre">conference_date</span></code> is a date instance holding 29 June 2006, then
<code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">conference_date|timeuntil</span> <span class="pre">}}</span></code> will return “4 weeks”.</p>
<p>Takes an optional argument that is a variable containing the date to use as
the comparison point (instead of <em>now</em>). If <code class="docutils literal notranslate"><span class="pre">from_date</span></code> contains 22 June
2006, then the following will return “1 week”:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">conference_date</span><span class="o">|</span><span class="nf">timeuntil</span><span class="o">:</span><span class="nv">from_date</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>Comparing offset-naive and offset-aware datetimes will return an empty string.</p>
<p>Minutes is the smallest unit used, and “0 minutes” will be returned for any
date that is in the past relative to the comparison point.</p>
</section>
<section id="s-title">
<span id="s-std-templatefilter-title"></span><span id="title"></span><span id="std-templatefilter-title"></span><h3><code class="docutils literal notranslate"><span class="pre">title</span></code><a class="headerlink" href="#title" title="Link to this heading">¶</a></h3>
<p>Converts a string into titlecase by making words start with an uppercase
character and the remaining characters lowercase. This tag makes no effort to
keep “trivial words” in lowercase.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">title</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;my</span> <span class="pre">FIRST</span> <span class="pre">post&quot;</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">&quot;My</span> <span class="pre">First</span> <span class="pre">Post&quot;</span></code>.</p>
</section>
<section id="s-truncatechars">
<span id="s-std-templatefilter-truncatechars"></span><span id="truncatechars"></span><span id="std-templatefilter-truncatechars"></span><h3><code class="docutils literal notranslate"><span class="pre">truncatechars</span></code><a class="headerlink" href="#truncatechars" title="Link to this heading">¶</a></h3>
<p>Truncates a string if it is longer than the specified number of characters.
Truncated strings will end with a translatable ellipsis character (”…”).</p>
<p><strong>Argument:</strong> Number of characters to truncate to</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">truncatechars</span><span class="o">:</span><span class="m">7</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug&quot;</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">&quot;Joel</span> <span class="pre">i…&quot;</span></code>.</p>
</section>
<section id="s-truncatechars-html">
<span id="s-std-templatefilter-truncatechars_html"></span><span id="truncatechars-html"></span><span id="std-templatefilter-truncatechars_html"></span><h3><code class="docutils literal notranslate"><span class="pre">truncatechars_html</span></code><a class="headerlink" href="#truncatechars-html" title="Link to this heading">¶</a></h3>
<p>Similar to <a class="reference internal" href="#std-templatefilter-truncatechars"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">truncatechars</span></code></a>, except that it is aware of HTML tags. Any
tags that are opened in the string and not closed before the truncation point
are closed immediately after the truncation.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">truncatechars_html</span><span class="o">:</span><span class="m">7</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;&lt;p&gt;Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug&lt;/p&gt;&quot;</span></code>, the output will be
<code class="docutils literal notranslate"><span class="pre">&quot;&lt;p&gt;Joel</span> <span class="pre">i…&lt;/p&gt;&quot;</span></code>.</p>
<p>Newlines in the HTML content will be preserved.</p>
<div class="admonition-size-of-input-string admonition">
<p class="admonition-title">Size of input string</p>
<p>Processing large, potentially malformed HTML strings can be
resource-intensive and impact service performance. <code class="docutils literal notranslate"><span class="pre">truncatechars_html</span></code>
limits input to the first five million characters.</p>
</div>
</section>
<section id="s-truncatewords">
<span id="s-std-templatefilter-truncatewords"></span><span id="truncatewords"></span><span id="std-templatefilter-truncatewords"></span><h3><code class="docutils literal notranslate"><span class="pre">truncatewords</span></code><a class="headerlink" href="#truncatewords" title="Link to this heading">¶</a></h3>
<p>Truncates a string after a certain number of words.</p>
<p><strong>Argument:</strong> Number of words to truncate after</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">truncatewords</span><span class="o">:</span><span class="m">2</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug&quot;</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">&quot;Joel</span> <span class="pre">is</span> <span class="pre">…&quot;</span></code>.</p>
<p>Newlines within the string will be removed.</p>
</section>
<section id="s-truncatewords-html">
<span id="s-std-templatefilter-truncatewords_html"></span><span id="truncatewords-html"></span><span id="std-templatefilter-truncatewords_html"></span><h3><code class="docutils literal notranslate"><span class="pre">truncatewords_html</span></code><a class="headerlink" href="#truncatewords-html" title="Link to this heading">¶</a></h3>
<p>Similar to <a class="reference internal" href="#std-templatefilter-truncatewords"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">truncatewords</span></code></a>, except that it is aware of HTML tags. Any
tags that are opened in the string and not closed before the truncation point,
are closed immediately after the truncation.</p>
<p>This is less efficient than <a class="reference internal" href="#std-templatefilter-truncatewords"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">truncatewords</span></code></a>, so should only be used
when it is being passed HTML text.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">truncatewords_html</span><span class="o">:</span><span class="m">2</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;&lt;p&gt;Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug&lt;/p&gt;&quot;</span></code>, the output will be
<code class="docutils literal notranslate"><span class="pre">&quot;&lt;p&gt;Joel</span> <span class="pre">is</span> <span class="pre">…&lt;/p&gt;&quot;</span></code>.</p>
<p>Newlines in the HTML content will be preserved.</p>
<div class="admonition-size-of-input-string admonition">
<p class="admonition-title">Size of input string</p>
<p>Processing large, potentially malformed HTML strings can be
resource-intensive and impact service performance. <code class="docutils literal notranslate"><span class="pre">truncatewords_html</span></code>
limits input to the first five million characters.</p>
</div>
</section>
<section id="s-unordered-list">
<span id="s-std-templatefilter-unordered_list"></span><span id="unordered-list"></span><span id="std-templatefilter-unordered_list"></span><h3><code class="docutils literal notranslate"><span class="pre">unordered_list</span></code><a class="headerlink" href="#unordered-list" title="Link to this heading">¶</a></h3>
<p>Recursively takes a self-nested list and returns an HTML unordered list –
WITHOUT opening and closing <code class="docutils literal notranslate"><span class="pre">&lt;ul&gt;</span></code> tags.</p>
<p>The list is assumed to be in the proper format. For example, if <code class="docutils literal notranslate"><span class="pre">var</span></code>
contains <code class="docutils literal notranslate"><span class="pre">['States',</span> <span class="pre">['Kansas',</span> <span class="pre">['Lawrence',</span> <span class="pre">'Topeka'],</span> <span class="pre">'Illinois']]</span></code>, then
<code class="docutils literal notranslate"><span class="pre">{{</span> <span class="pre">var|unordered_list</span> <span class="pre">}}</span></code> would return:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;</span>States
<span class="p">&lt;</span><span class="nt">ul</span><span class="p">&gt;</span>
        <span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;</span>Kansas
        <span class="p">&lt;</span><span class="nt">ul</span><span class="p">&gt;</span>
                <span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;</span>Lawrence<span class="p">&lt;/</span><span class="nt">li</span><span class="p">&gt;</span>
                <span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;</span>Topeka<span class="p">&lt;/</span><span class="nt">li</span><span class="p">&gt;</span>
        <span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span>
        <span class="p">&lt;/</span><span class="nt">li</span><span class="p">&gt;</span>
        <span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;</span>Illinois<span class="p">&lt;/</span><span class="nt">li</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">li</span><span class="p">&gt;</span>
</pre></div>
</div>
</section>
<section id="s-upper">
<span id="s-std-templatefilter-upper"></span><span id="upper"></span><span id="std-templatefilter-upper"></span><h3><code class="docutils literal notranslate"><span class="pre">upper</span></code><a class="headerlink" href="#upper" title="Link to this heading">¶</a></h3>
<p>Converts a string into all uppercase.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">upper</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug&quot;</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">&quot;JOEL</span> <span class="pre">IS</span> <span class="pre">A</span> <span class="pre">SLUG&quot;</span></code>.</p>
</section>
<section id="s-urlencode">
<span id="s-std-templatefilter-urlencode"></span><span id="urlencode"></span><span id="std-templatefilter-urlencode"></span><h3><code class="docutils literal notranslate"><span class="pre">urlencode</span></code><a class="headerlink" href="#urlencode" title="Link to this heading">¶</a></h3>
<p>Escapes a value for use in a URL.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">urlencode</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;https://www.example.org/foo?a=b&amp;c=d&quot;</span></code>, the output will be
<code class="docutils literal notranslate"><span class="pre">&quot;https%3A//www.example.org/foo%3Fa%3Db%26c%3Dd&quot;</span></code>.</p>
<p>An optional argument containing the characters which should not be escaped can
be provided.</p>
<p>If not provided, the ‘/’ character is assumed safe. An empty string can be
provided when <em>all</em> characters should be escaped. For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">urlencode</span><span class="s2">:&quot;&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;https://www.example.org/&quot;</span></code>, the output will be
<code class="docutils literal notranslate"><span class="pre">&quot;https%3A%2F%2Fwww.example.org%2F&quot;</span></code>.</p>
</section>
<section id="s-urlize">
<span id="s-std-templatefilter-urlize"></span><span id="urlize"></span><span id="std-templatefilter-urlize"></span><h3><code class="docutils literal notranslate"><span class="pre">urlize</span></code><a class="headerlink" href="#urlize" title="Link to this heading">¶</a></h3>
<p>Converts URLs and email addresses in text into clickable links.</p>
<p>This template tag works on links prefixed with <code class="docutils literal notranslate"><span class="pre">http://</span></code>, <code class="docutils literal notranslate"><span class="pre">https://</span></code>, or
<code class="docutils literal notranslate"><span class="pre">www.</span></code>. For example, <code class="docutils literal notranslate"><span class="pre">https://djangocon.eu</span></code> will get converted but
<code class="docutils literal notranslate"><span class="pre">djangocon.eu</span></code> won’t.</p>
<p>It also supports domain-only links ending in one of the original top level
domains (<code class="docutils literal notranslate"><span class="pre">.com</span></code>, <code class="docutils literal notranslate"><span class="pre">.edu</span></code>, <code class="docutils literal notranslate"><span class="pre">.gov</span></code>, <code class="docutils literal notranslate"><span class="pre">.int</span></code>, <code class="docutils literal notranslate"><span class="pre">.mil</span></code>, <code class="docutils literal notranslate"><span class="pre">.net</span></code>, and
<code class="docutils literal notranslate"><span class="pre">.org</span></code>). For example, <code class="docutils literal notranslate"><span class="pre">djangoproject.com</span></code> gets converted.</p>
<p>Links can have trailing punctuation (periods, commas, close-parens) and leading
punctuation (opening parens), and <code class="docutils literal notranslate"><span class="pre">urlize</span></code> will still do the right thing.</p>
<p>Links generated by <code class="docutils literal notranslate"><span class="pre">urlize</span></code> have a <code class="docutils literal notranslate"><span class="pre">rel=&quot;nofollow&quot;</span></code> attribute added
to them.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">urlize</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;Check</span> <span class="pre">out</span> <span class="pre">www.djangoproject.com&quot;</span></code>, the output will be:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>Check out <span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;http://www.djangoproject.com&quot;</span> <span class="na">rel</span><span class="o">=</span><span class="s">&quot;nofollow&quot;</span><span class="p">&gt;</span>www.djangoproject.com<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
</pre></div>
</div>
<div class="deprecated">
<p><span class="versionmodified deprecated">Deprecated since version 6.0: </span>The default protocol when none is provided will change from HTTP to HTTPS
in Django 7.0. Hence, the output will become:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>Check out <span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;https://www.djangoproject.com&quot;</span> <span class="na">rel</span><span class="o">=</span><span class="s">&quot;nofollow&quot;</span><span class="p">&gt;</span>www.djangoproject.com<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>Set the transitional setting <a class="reference internal" href="../settings.html#std-setting-URLIZE_ASSUME_HTTPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">URLIZE_ASSUME_HTTPS</span></code></a> to <code class="docutils literal notranslate"><span class="pre">True</span></code> to
opt into using HTTPS during the Django 6.x release cycle.</p>
</div>
<p>In addition to web links, <code class="docutils literal notranslate"><span class="pre">urlize</span></code> also converts email addresses into
<code class="docutils literal notranslate"><span class="pre">mailto:</span></code> links. If <code class="docutils literal notranslate"><span class="pre">value</span></code> is
<code class="docutils literal notranslate"><span class="pre">&quot;Send</span> <span class="pre">questions</span> <span class="pre">to</span> <span class="pre">foo&#64;example.com&quot;</span></code>, the output will be
<code class="docutils literal notranslate"><span class="pre">&quot;Send</span> <span class="pre">questions</span> <span class="pre">to</span> <span class="pre">&lt;a</span> <span class="pre">href=&quot;mailto:foo&#64;example.com&quot;&gt;foo&#64;example.com&lt;/a&gt;&quot;</span></code>.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">urlize</span></code> filter also takes an optional parameter <code class="docutils literal notranslate"><span class="pre">autoescape</span></code>. If
<code class="docutils literal notranslate"><span class="pre">autoescape</span></code> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, the link text and URLs will be escaped using
Django’s built-in <a class="reference internal" href="#std-templatefilter-escape"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">escape</span></code></a> filter. The default value for
<code class="docutils literal notranslate"><span class="pre">autoescape</span></code> is <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If <code class="docutils literal notranslate"><span class="pre">urlize</span></code> is applied to text that already contains HTML markup, or to
email addresses that contain single quotes (<code class="docutils literal notranslate"><span class="pre">'</span></code>), things won’t work as
expected. Apply this filter only to plain text.</p>
</div>
</section>
<section id="s-urlizetrunc">
<span id="s-std-templatefilter-urlizetrunc"></span><span id="urlizetrunc"></span><span id="std-templatefilter-urlizetrunc"></span><h3><code class="docutils literal notranslate"><span class="pre">urlizetrunc</span></code><a class="headerlink" href="#urlizetrunc" title="Link to this heading">¶</a></h3>
<p>Converts URLs and email addresses into clickable links just like <a class="reference internal" href="#urlize">urlize</a>, but
truncates URLs longer than the given character limit.</p>
<p><strong>Argument:</strong> Number of characters that link text should be truncated to,
including the ellipsis that’s added if truncation is necessary.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">urlizetrunc</span><span class="o">:</span><span class="m">15</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;Check</span> <span class="pre">out</span> <span class="pre">www.djangoproject.com&quot;</span></code>, the output would be:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>Check out <span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;http://www.djangoproject.com&quot;</span> <span class="na">rel</span><span class="o">=</span><span class="s">&quot;nofollow&quot;</span><span class="p">&gt;</span>www.djangoproj…<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
</pre></div>
</div>
<div class="deprecated">
<p><span class="versionmodified deprecated">Deprecated since version 6.0: </span>The default protocol when none is provided will change from HTTP to HTTPS
in Django 7.0. Hence, the output will become:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>Check out <span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;https://www.djangoproject.com&quot;</span> <span class="na">rel</span><span class="o">=</span><span class="s">&quot;nofollow&quot;</span><span class="p">&gt;</span>www.djangoproj…<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>Set the transitional setting <a class="reference internal" href="../settings.html#std-setting-URLIZE_ASSUME_HTTPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">URLIZE_ASSUME_HTTPS</span></code></a> to <code class="docutils literal notranslate"><span class="pre">True</span></code> to
opt into using HTTPS during the Django 6.x release cycle.</p>
</div>
<p>As with <a class="reference internal" href="#urlize">urlize</a>, this filter should only be applied to plain text.</p>
</section>
<section id="s-wordcount">
<span id="s-std-templatefilter-wordcount"></span><span id="wordcount"></span><span id="std-templatefilter-wordcount"></span><h3><code class="docutils literal notranslate"><span class="pre">wordcount</span></code><a class="headerlink" href="#wordcount" title="Link to this heading">¶</a></h3>
<p>Returns the number of words.</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">wordcount</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug&quot;</span></code>, the output will be <code class="docutils literal notranslate"><span class="pre">4</span></code>.</p>
</section>
<section id="s-wordwrap">
<span id="s-std-templatefilter-wordwrap"></span><span id="wordwrap"></span><span id="std-templatefilter-wordwrap"></span><h3><code class="docutils literal notranslate"><span class="pre">wordwrap</span></code><a class="headerlink" href="#wordwrap" title="Link to this heading">¶</a></h3>
<p>Wraps words at specified line length.</p>
<p><strong>Argument:</strong> number of characters at which to wrap the text</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">wordwrap</span><span class="o">:</span><span class="m">5</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">value</span></code> is <code class="docutils literal notranslate"><span class="pre">Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug</span></code>, the output would be:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span>Joel
is a
slug
</pre></div>
</div>
</section>
<section id="s-yesno">
<span id="s-std-templatefilter-yesno"></span><span id="yesno"></span><span id="std-templatefilter-yesno"></span><h3><code class="docutils literal notranslate"><span class="pre">yesno</span></code><a class="headerlink" href="#yesno" title="Link to this heading">¶</a></h3>
<p>Maps values for <code class="docutils literal notranslate"><span class="pre">True</span></code>, <code class="docutils literal notranslate"><span class="pre">False</span></code>, and (optionally) <code class="docutils literal notranslate"><span class="pre">None</span></code>, to the strings
“yes”, “no”, “maybe”, or a custom mapping passed as a comma-separated list, and
returns one of those strings according to the value:</p>
<p>For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">yesno</span><span class="s2">:&quot;yeah,no,maybe&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<table class="docutils">
<thead>
<tr class="row-odd"><th class="head"><p>Value</p></th>
<th class="head"><p>Argument</p></th>
<th class="head"><p>Outputs</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">True</span></code></p></td>
<td></td>
<td><p><code class="docutils literal notranslate"><span class="pre">yes</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">True</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;yeah,no,maybe&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">yeah</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">False</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;yeah,no,maybe&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">no</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">None</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;yeah,no,maybe&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">maybe</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">None</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;yeah,no&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">no</span></code> (converts <code class="docutils literal notranslate"><span class="pre">None</span></code> to <code class="docutils literal notranslate"><span class="pre">False</span></code>
if no mapping for <code class="docutils literal notranslate"><span class="pre">None</span></code> is given)</p></td>
</tr>
</tbody>
</table>
</section>
</section>
<section id="s-internationalization-tags-and-filters">
<span id="internationalization-tags-and-filters"></span><h2>Internationalization tags and filters<a class="headerlink" href="#internationalization-tags-and-filters" title="Link to this heading">¶</a></h2>
<p>Django provides template tags and filters to control each aspect of
<a class="reference internal" href="../../topics/i18n/index.html"><span class="doc">internationalization</span></a> in templates. They allow for
granular control of translations, formatting, and time zone conversions.</p>
<section id="s-i18n">
<span id="i18n"></span><h3><code class="docutils literal notranslate"><span class="pre">i18n</span></code><a class="headerlink" href="#i18n" title="Link to this heading">¶</a></h3>
<p>This library allows specifying translatable text in templates.
To enable it, set <a class="reference internal" href="../settings.html#std-setting-USE_I18N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_I18N</span></code></a> to <code class="docutils literal notranslate"><span class="pre">True</span></code>, then load it with
<code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">i18n</span> <span class="pre">%}</span></code>.</p>
<p>See <a class="reference internal" href="../../topics/i18n/translation.html#specifying-translation-strings-in-template-code"><span class="std std-ref">Internationalization: in template code</span></a>.</p>
</section>
<section id="s-l10n">
<span id="l10n"></span><h3><code class="docutils literal notranslate"><span class="pre">l10n</span></code><a class="headerlink" href="#l10n" title="Link to this heading">¶</a></h3>
<p>This library provides control over the localization of values in templates.
You only need to load the library using <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">l10n</span> <span class="pre">%}</span></code>.</p>
<p>See <a class="reference internal" href="../../topics/i18n/formatting.html#topic-l10n-templates"><span class="std std-ref">Controlling localization in templates</span></a>.</p>
</section>
<section id="s-tz">
<span id="tz"></span><h3><code class="docutils literal notranslate"><span class="pre">tz</span></code><a class="headerlink" href="#tz" title="Link to this heading">¶</a></h3>
<p>This library provides control over time zone conversions in templates.
Like <code class="docutils literal notranslate"><span class="pre">l10n</span></code>, you only need to load the library using <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">tz</span> <span class="pre">%}</span></code>,
but you’ll usually also set <a class="reference internal" href="../settings.html#std-setting-USE_TZ"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_TZ</span></code></a> to <code class="docutils literal notranslate"><span class="pre">True</span></code> so that conversion
to local time happens by default.</p>
<p>See <a class="reference internal" href="../../topics/i18n/timezones.html#time-zones-in-templates"><span class="std std-ref">Time zone aware output in templates</span></a>.</p>
</section>
</section>
<section id="s-other-tags-and-filters-libraries">
<span id="other-tags-and-filters-libraries"></span><h2>Other tags and filters libraries<a class="headerlink" href="#other-tags-and-filters-libraries" title="Link to this heading">¶</a></h2>
<p>Django comes with a couple of other template-tag libraries that you have to
enable explicitly in your <a class="reference internal" href="../settings.html#std-setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code></a> setting and enable in your
template with the <a class="reference internal" href="#std-templatetag-load"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">%}</span></code></a> tag.</p>
<section id="s-django-contrib-humanize">
<span id="django-contrib-humanize"></span><h3><code class="docutils literal notranslate"><span class="pre">django.contrib.humanize</span></code><a class="headerlink" href="#django-contrib-humanize" title="Link to this heading">¶</a></h3>
<p>A set of Django template filters useful for adding a “human touch” to data. See
<a class="reference internal" href="../contrib/humanize.html"><span class="doc">django.contrib.humanize</span></a>.</p>
</section>
<section id="s-static">
<span id="static"></span><h3><code class="docutils literal notranslate"><span class="pre">static</span></code><a class="headerlink" href="#static" title="Link to this heading">¶</a></h3>
<section id="s-std-templatetag-static">
<span id="s-id7"></span><span id="std-templatetag-static"></span><span id="id7"></span><h4><code class="docutils literal notranslate"><span class="pre">static</span></code><a class="headerlink" href="#std-templatetag-static" title="Link to this heading">¶</a></h4>
<p>To link to static files that are saved in <a class="reference internal" href="../settings.html#std-setting-STATIC_ROOT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_ROOT</span></code></a> Django ships
with a <a class="reference internal" href="#std-templatetag-static"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">static</span></code></a> template tag. If the <a class="reference internal" href="../contrib/staticfiles.html#module-django.contrib.staticfiles" title="django.contrib.staticfiles: An app for handling static files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.staticfiles</span></code></a>
app is installed, the tag will serve files using <code class="docutils literal notranslate"><span class="pre">url()</span></code> method of the
storage specified by <code class="docutils literal notranslate"><span class="pre">staticfiles</span></code> in <a class="reference internal" href="../settings.html#std-setting-STORAGES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STORAGES</span></code></a>. For example:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">load</span> <span class="nv">static</span> <span class="cp">%}</span>
<span class="p">&lt;</span><span class="nt">img</span> <span class="na">src</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">static</span> <span class="s1">&#39;images/hi.jpg&#39;</span> <span class="cp">%}</span><span class="s">&quot;</span> <span class="na">alt</span><span class="o">=</span><span class="s">&quot;Hi!&quot;</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>It is also able to consume standard context variables, e.g. assuming a
<code class="docutils literal notranslate"><span class="pre">user_stylesheet</span></code> variable is passed to the template:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">load</span> <span class="nv">static</span> <span class="cp">%}</span>
<span class="p">&lt;</span><span class="nt">link</span> <span class="na">rel</span><span class="o">=</span><span class="s">&quot;stylesheet&quot;</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">static</span> <span class="nv">user_stylesheet</span> <span class="cp">%}</span><span class="s">&quot;</span> <span class="na">media</span><span class="o">=</span><span class="s">&quot;screen&quot;</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>If you’d like to retrieve a static URL without displaying it, you can use a
slightly different call:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">load</span> <span class="nv">static</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">static</span> <span class="s2">&quot;images/hi.jpg&quot;</span> <span class="k">as</span> <span class="nv">myphoto</span> <span class="cp">%}</span>
<span class="p">&lt;</span><span class="nt">img</span> <span class="na">src</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">myphoto</span> <span class="cp">}}</span><span class="s">&quot;</span> <span class="na">alt</span><span class="o">=</span><span class="s">&quot;Hi!&quot;</span><span class="p">&gt;</span>
</pre></div>
</div>
<div class="admonition-using-jinja2-templates admonition">
<p class="admonition-title">Using Jinja2 templates?</p>
<p>See <a class="reference internal" href="../../topics/templates.html#django.template.backends.jinja2.Jinja2" title="django.template.backends.jinja2.Jinja2"><code class="xref py py-class docutils literal notranslate"><span class="pre">Jinja2</span></code></a> for information on
using the <code class="docutils literal notranslate"><span class="pre">static</span></code> tag with Jinja2.</p>
</div>
</section>
<section id="s-get-static-prefix">
<span id="s-std-templatetag-get_static_prefix"></span><span id="get-static-prefix"></span><span id="std-templatetag-get_static_prefix"></span><h4><code class="docutils literal notranslate"><span class="pre">get_static_prefix</span></code><a class="headerlink" href="#get-static-prefix" title="Link to this heading">¶</a></h4>
<p>You should prefer the <a class="reference internal" href="#std-templatetag-static"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">static</span></code></a> template tag, but if you need more control
over exactly where and how <a class="reference internal" href="../settings.html#std-setting-STATIC_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_URL</span></code></a> is injected into the template,
you can use the <a class="reference internal" href="#std-templatetag-get_static_prefix"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">get_static_prefix</span></code></a> template tag:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">load</span> <span class="nv">static</span> <span class="cp">%}</span>
<span class="p">&lt;</span><span class="nt">img</span> <span class="na">src</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">get_static_prefix</span> <span class="cp">%}</span><span class="s">images/hi.jpg&quot;</span> <span class="na">alt</span><span class="o">=</span><span class="s">&quot;Hi!&quot;</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>There’s also a second form you can use to avoid extra processing if you need
the value multiple times:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">load</span> <span class="nv">static</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">get_static_prefix</span> <span class="k">as</span> <span class="nv">STATIC_PREFIX</span> <span class="cp">%}</span>

<span class="p">&lt;</span><span class="nt">img</span> <span class="na">src</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">STATIC_PREFIX</span> <span class="cp">}}</span><span class="s">images/hi.jpg&quot;</span> <span class="na">alt</span><span class="o">=</span><span class="s">&quot;Hi!&quot;</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">img</span> <span class="na">src</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">STATIC_PREFIX</span> <span class="cp">}}</span><span class="s">images/hi2.jpg&quot;</span> <span class="na">alt</span><span class="o">=</span><span class="s">&quot;Hello!&quot;</span><span class="p">&gt;</span>
</pre></div>
</div>
</section>
<section id="s-get-media-prefix">
<span id="s-std-templatetag-get_media_prefix"></span><span id="get-media-prefix"></span><span id="std-templatetag-get_media_prefix"></span><h4><code class="docutils literal notranslate"><span class="pre">get_media_prefix</span></code><a class="headerlink" href="#get-media-prefix" title="Link to this heading">¶</a></h4>
<p>Similar to the <a class="reference internal" href="#std-templatetag-get_static_prefix"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">get_static_prefix</span></code></a>, <code class="docutils literal notranslate"><span class="pre">get_media_prefix</span></code> populates a
template variable with the media prefix <a class="reference internal" href="../settings.html#std-setting-MEDIA_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MEDIA_URL</span></code></a>, e.g.:</p>
<div class="highlight-html+django notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">load</span> <span class="nv">static</span> <span class="cp">%}</span>
<span class="p">&lt;</span><span class="nt">body</span> <span class="na">data-media-url</span><span class="o">=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">get_media_prefix</span> <span class="cp">%}</span><span class="s">&quot;</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>By storing the value in a data attribute, we ensure it’s escaped appropriately
if we want to use it in a JavaScript context.</p>
</section>
</section>
</section>
</section>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
  <div>
    <h3><a href="../../contents.html">Table of Contents</a></h3>
    <ul>
<li><a class="reference internal" href="#">Built-in template tags and filters</a><ul>
<li><a class="reference internal" href="#built-in-tag-reference">Built-in tag reference</a><ul>
<li><a class="reference internal" href="#autoescape"><code class="docutils literal notranslate"><span class="pre">autoescape</span></code></a></li>
<li><a class="reference internal" href="#block"><code class="docutils literal notranslate"><span class="pre">block</span></code></a></li>
<li><a class="reference internal" href="#comment"><code class="docutils literal notranslate"><span class="pre">comment</span></code></a></li>
<li><a class="reference internal" href="#csrf-token"><code class="docutils literal notranslate"><span class="pre">csrf_token</span></code></a></li>
<li><a class="reference internal" href="#cycle"><code class="docutils literal notranslate"><span class="pre">cycle</span></code></a></li>
<li><a class="reference internal" href="#debug"><code class="docutils literal notranslate"><span class="pre">debug</span></code></a></li>
<li><a class="reference internal" href="#extends"><code class="docutils literal notranslate"><span class="pre">extends</span></code></a></li>
<li><a class="reference internal" href="#filter"><code class="docutils literal notranslate"><span class="pre">filter</span></code></a></li>
<li><a class="reference internal" href="#firstof"><code class="docutils literal notranslate"><span class="pre">firstof</span></code></a></li>
<li><a class="reference internal" href="#for"><code class="docutils literal notranslate"><span class="pre">for</span></code></a></li>
<li><a class="reference internal" href="#for-empty"><code class="docutils literal notranslate"><span class="pre">for</span></code> … <code class="docutils literal notranslate"><span class="pre">empty</span></code></a></li>
<li><a class="reference internal" href="#if"><code class="docutils literal notranslate"><span class="pre">if</span></code></a><ul>
<li><a class="reference internal" href="#boolean-operators">Boolean operators</a><ul>
<li><a class="reference internal" href="#operator"><code class="docutils literal notranslate"><span class="pre">==</span></code> operator</a></li>
<li><a class="reference internal" href="#id1"><code class="docutils literal notranslate"><span class="pre">!=</span></code> operator</a></li>
<li><a class="reference internal" href="#id2"><code class="docutils literal notranslate"><span class="pre">&lt;</span></code> operator</a></li>
<li><a class="reference internal" href="#id3"><code class="docutils literal notranslate"><span class="pre">&gt;</span></code> operator</a></li>
<li><a class="reference internal" href="#id4"><code class="docutils literal notranslate"><span class="pre">&lt;=</span></code> operator</a></li>
<li><a class="reference internal" href="#id5"><code class="docutils literal notranslate"><span class="pre">&gt;=</span></code> operator</a></li>
<li><a class="reference internal" href="#in-operator"><code class="docutils literal notranslate"><span class="pre">in</span></code> operator</a></li>
<li><a class="reference internal" href="#not-in-operator"><code class="docutils literal notranslate"><span class="pre">not</span> <span class="pre">in</span></code> operator</a></li>
<li><a class="reference internal" href="#is-operator"><code class="docutils literal notranslate"><span class="pre">is</span></code> operator</a></li>
<li><a class="reference internal" href="#is-not-operator"><code class="docutils literal notranslate"><span class="pre">is</span> <span class="pre">not</span></code> operator</a></li>
</ul>
</li>
<li><a class="reference internal" href="#filters">Filters</a></li>
<li><a class="reference internal" href="#complex-expressions">Complex expressions</a></li>
</ul>
</li>
<li><a class="reference internal" href="#ifchanged"><code class="docutils literal notranslate"><span class="pre">ifchanged</span></code></a></li>
<li><a class="reference internal" href="#include"><code class="docutils literal notranslate"><span class="pre">include</span></code></a></li>
<li><a class="reference internal" href="#load"><code class="docutils literal notranslate"><span class="pre">load</span></code></a></li>
<li><a class="reference internal" href="#lorem"><code class="docutils literal notranslate"><span class="pre">lorem</span></code></a></li>
<li><a class="reference internal" href="#now"><code class="docutils literal notranslate"><span class="pre">now</span></code></a></li>
<li><a class="reference internal" href="#partial"><code class="docutils literal notranslate"><span class="pre">partial</span></code></a></li>
<li><a class="reference internal" href="#partialdef"><code class="docutils literal notranslate"><span class="pre">partialdef</span></code></a></li>
<li><a class="reference internal" href="#querystring"><code class="docutils literal notranslate"><span class="pre">querystring</span></code></a><ul>
<li><a class="reference internal" href="#basic-usage">Basic usage</a></li>
<li><a class="reference internal" href="#setting-items">Setting items</a></li>
<li><a class="reference internal" href="#removing-items">Removing items</a></li>
<li><a class="reference internal" href="#handling-lists">Handling lists</a></li>
<li><a class="reference internal" href="#customizing-the-base-querydict">Customizing the base QueryDict</a></li>
<li><a class="reference internal" href="#dynamic-usage">Dynamic usage</a></li>
</ul>
</li>
<li><a class="reference internal" href="#regroup"><code class="docutils literal notranslate"><span class="pre">regroup</span></code></a><ul>
<li><a class="reference internal" href="#grouping-on-other-properties">Grouping on other properties</a></li>
</ul>
</li>
<li><a class="reference internal" href="#resetcycle"><code class="docutils literal notranslate"><span class="pre">resetcycle</span></code></a></li>
<li><a class="reference internal" href="#spaceless"><code class="docutils literal notranslate"><span class="pre">spaceless</span></code></a></li>
<li><a class="reference internal" href="#templatetag"><code class="docutils literal notranslate"><span class="pre">templatetag</span></code></a></li>
<li><a class="reference internal" href="#url"><code class="docutils literal notranslate"><span class="pre">url</span></code></a></li>
<li><a class="reference internal" href="#verbatim"><code class="docutils literal notranslate"><span class="pre">verbatim</span></code></a></li>
<li><a class="reference internal" href="#widthratio"><code class="docutils literal notranslate"><span class="pre">widthratio</span></code></a></li>
<li><a class="reference internal" href="#with"><code class="docutils literal notranslate"><span class="pre">with</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#built-in-filter-reference">Built-in filter reference</a><ul>
<li><a class="reference internal" href="#add"><code class="docutils literal notranslate"><span class="pre">add</span></code></a></li>
<li><a class="reference internal" href="#addslashes"><code class="docutils literal notranslate"><span class="pre">addslashes</span></code></a></li>
<li><a class="reference internal" href="#capfirst"><code class="docutils literal notranslate"><span class="pre">capfirst</span></code></a></li>
<li><a class="reference internal" href="#center"><code class="docutils literal notranslate"><span class="pre">center</span></code></a></li>
<li><a class="reference internal" href="#cut"><code class="docutils literal notranslate"><span class="pre">cut</span></code></a></li>
<li><a class="reference internal" href="#date"><code class="docutils literal notranslate"><span class="pre">date</span></code></a></li>
<li><a class="reference internal" href="#default"><code class="docutils literal notranslate"><span class="pre">default</span></code></a></li>
<li><a class="reference internal" href="#default-if-none"><code class="docutils literal notranslate"><span class="pre">default_if_none</span></code></a></li>
<li><a class="reference internal" href="#dictsort"><code class="docutils literal notranslate"><span class="pre">dictsort</span></code></a></li>
<li><a class="reference internal" href="#dictsortreversed"><code class="docutils literal notranslate"><span class="pre">dictsortreversed</span></code></a></li>
<li><a class="reference internal" href="#divisibleby"><code class="docutils literal notranslate"><span class="pre">divisibleby</span></code></a></li>
<li><a class="reference internal" href="#escape"><code class="docutils literal notranslate"><span class="pre">escape</span></code></a></li>
<li><a class="reference internal" href="#escapejs"><code class="docutils literal notranslate"><span class="pre">escapejs</span></code></a></li>
<li><a class="reference internal" href="#escapeseq"><code class="docutils literal notranslate"><span class="pre">escapeseq</span></code></a></li>
<li><a class="reference internal" href="#filesizeformat"><code class="docutils literal notranslate"><span class="pre">filesizeformat</span></code></a></li>
<li><a class="reference internal" href="#first"><code class="docutils literal notranslate"><span class="pre">first</span></code></a></li>
<li><a class="reference internal" href="#floatformat"><code class="docutils literal notranslate"><span class="pre">floatformat</span></code></a></li>
<li><a class="reference internal" href="#force-escape"><code class="docutils literal notranslate"><span class="pre">force_escape</span></code></a></li>
<li><a class="reference internal" href="#get-digit"><code class="docutils literal notranslate"><span class="pre">get_digit</span></code></a></li>
<li><a class="reference internal" href="#iriencode"><code class="docutils literal notranslate"><span class="pre">iriencode</span></code></a></li>
<li><a class="reference internal" href="#join"><code class="docutils literal notranslate"><span class="pre">join</span></code></a></li>
<li><a class="reference internal" href="#json-script"><code class="docutils literal notranslate"><span class="pre">json_script</span></code></a></li>
<li><a class="reference internal" href="#last"><code class="docutils literal notranslate"><span class="pre">last</span></code></a></li>
<li><a class="reference internal" href="#length"><code class="docutils literal notranslate"><span class="pre">length</span></code></a></li>
<li><a class="reference internal" href="#linebreaks"><code class="docutils literal notranslate"><span class="pre">linebreaks</span></code></a></li>
<li><a class="reference internal" href="#linebreaksbr"><code class="docutils literal notranslate"><span class="pre">linebreaksbr</span></code></a></li>
<li><a class="reference internal" href="#linenumbers"><code class="docutils literal notranslate"><span class="pre">linenumbers</span></code></a></li>
<li><a class="reference internal" href="#ljust"><code class="docutils literal notranslate"><span class="pre">ljust</span></code></a></li>
<li><a class="reference internal" href="#lower"><code class="docutils literal notranslate"><span class="pre">lower</span></code></a></li>
<li><a class="reference internal" href="#make-list"><code class="docutils literal notranslate"><span class="pre">make_list</span></code></a></li>
<li><a class="reference internal" href="#phone2numeric"><code class="docutils literal notranslate"><span class="pre">phone2numeric</span></code></a></li>
<li><a class="reference internal" href="#pluralize"><code class="docutils literal notranslate"><span class="pre">pluralize</span></code></a></li>
<li><a class="reference internal" href="#pprint"><code class="docutils literal notranslate"><span class="pre">pprint</span></code></a></li>
<li><a class="reference internal" href="#random"><code class="docutils literal notranslate"><span class="pre">random</span></code></a></li>
<li><a class="reference internal" href="#rjust"><code class="docutils literal notranslate"><span class="pre">rjust</span></code></a></li>
<li><a class="reference internal" href="#safe"><code class="docutils literal notranslate"><span class="pre">safe</span></code></a></li>
<li><a class="reference internal" href="#safeseq"><code class="docutils literal notranslate"><span class="pre">safeseq</span></code></a></li>
<li><a class="reference internal" href="#slice"><code class="docutils literal notranslate"><span class="pre">slice</span></code></a></li>
<li><a class="reference internal" href="#slugify"><code class="docutils literal notranslate"><span class="pre">slugify</span></code></a></li>
<li><a class="reference internal" href="#stringformat"><code class="docutils literal notranslate"><span class="pre">stringformat</span></code></a></li>
<li><a class="reference internal" href="#striptags"><code class="docutils literal notranslate"><span class="pre">striptags</span></code></a></li>
<li><a class="reference internal" href="#time"><code class="docutils literal notranslate"><span class="pre">time</span></code></a></li>
<li><a class="reference internal" href="#timesince"><code class="docutils literal notranslate"><span class="pre">timesince</span></code></a></li>
<li><a class="reference internal" href="#timeuntil"><code class="docutils literal notranslate"><span class="pre">timeuntil</span></code></a></li>
<li><a class="reference internal" href="#title"><code class="docutils literal notranslate"><span class="pre">title</span></code></a></li>
<li><a class="reference internal" href="#truncatechars"><code class="docutils literal notranslate"><span class="pre">truncatechars</span></code></a></li>
<li><a class="reference internal" href="#truncatechars-html"><code class="docutils literal notranslate"><span class="pre">truncatechars_html</span></code></a></li>
<li><a class="reference internal" href="#truncatewords"><code class="docutils literal notranslate"><span class="pre">truncatewords</span></code></a></li>
<li><a class="reference internal" href="#truncatewords-html"><code class="docutils literal notranslate"><span class="pre">truncatewords_html</span></code></a></li>
<li><a class="reference internal" href="#unordered-list"><code class="docutils literal notranslate"><span class="pre">unordered_list</span></code></a></li>
<li><a class="reference internal" href="#upper"><code class="docutils literal notranslate"><span class="pre">upper</span></code></a></li>
<li><a class="reference internal" href="#urlencode"><code class="docutils literal notranslate"><span class="pre">urlencode</span></code></a></li>
<li><a class="reference internal" href="#urlize"><code class="docutils literal notranslate"><span class="pre">urlize</span></code></a></li>
<li><a class="reference internal" href="#urlizetrunc"><code class="docutils literal notranslate"><span class="pre">urlizetrunc</span></code></a></li>
<li><a class="reference internal" href="#wordcount"><code class="docutils literal notranslate"><span class="pre">wordcount</span></code></a></li>
<li><a class="reference internal" href="#wordwrap"><code class="docutils literal notranslate"><span class="pre">wordwrap</span></code></a></li>
<li><a class="reference internal" href="#yesno"><code class="docutils literal notranslate"><span class="pre">yesno</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#internationalization-tags-and-filters">Internationalization tags and filters</a><ul>
<li><a class="reference internal" href="#i18n"><code class="docutils literal notranslate"><span class="pre">i18n</span></code></a></li>
<li><a class="reference internal" href="#l10n"><code class="docutils literal notranslate"><span class="pre">l10n</span></code></a></li>
<li><a class="reference internal" href="#tz"><code class="docutils literal notranslate"><span class="pre">tz</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#other-tags-and-filters-libraries">Other tags and filters libraries</a><ul>
<li><a class="reference internal" href="#django-contrib-humanize"><code class="docutils literal notranslate"><span class="pre">django.contrib.humanize</span></code></a></li>
<li><a class="reference internal" href="#static"><code class="docutils literal notranslate"><span class="pre">static</span></code></a><ul>
<li><a class="reference internal" href="#std-templatetag-static"><code class="docutils literal notranslate"><span class="pre">static</span></code></a></li>
<li><a class="reference internal" href="#get-static-prefix"><code class="docutils literal notranslate"><span class="pre">get_static_prefix</span></code></a></li>
<li><a class="reference internal" href="#get-media-prefix"><code class="docutils literal notranslate"><span class="pre">get_media_prefix</span></code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>

  </div>
  <div>
    <h4>Previous topic</h4>
    <p class="topless"><a href="language.html"
                          title="previous chapter">The Django template language</a></p>
  </div>
  <div>
    <h4>Next topic</h4>
    <p class="topless"><a href="api.html"
                          title="next chapter">The Django template language: for Python programmers</a></p>
  </div>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/ref/templates/builtins.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Nov 30, 2025</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="language.html" title="The Django template language">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="api.html" title="The Django template language: for Python programmers">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>