Sophie

Sophie

distrib > Fedora > 20 > i386 > by-pkgid > 422242acff54b9373d7d4b7f73232ce1 > files > 665

python3-django-doc-1.6.7-1.fc20.noarch.rpm


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Built-in template tags and filters &mdash; Django 1.6.7 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '1.6.7',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="Django 1.6.7 documentation" href="../../index.html" />
    <link rel="up" title="Templates" href="index.html" />
    <link rel="next" title="The Django template language: For Python programmers" href="api.html" />
    <link rel="prev" title="Templates" href="index.html" />



 
<script type="text/javascript" src="../../templatebuiltins.js"></script>
<script type="text/javascript">
(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 1.6.7 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="index.html" title="Templates">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">
            
  <div class="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="Permalink to this headline">¶</a></h1>
<p>This document describes Django&#8217;s built-in template tags and filters. It is
recommended that you use the <a class="reference internal" href="../contrib/admin/admindocs.html"><em>automatic documentation</em></a>, if available, as this will also include
documentation for any custom tags or filters installed.</p>
<div class="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="Permalink to this headline">¶</a></h2>
<div class="section" id="s-autoescape">
<span id="s-std:templatetag-autoescape"></span><span id="autoescape"></span><span id="std:templatetag-autoescape"></span><h3>autoescape<a class="headerlink" href="#autoescape" title="Permalink to this headline">¶</a></h3>
<p>Controls the current auto-escaping behavior. This tag takes either <tt class="docutils literal"><span class="pre">on</span></tt> or
<tt class="docutils literal"><span class="pre">off</span></tt> as an argument and that determines whether auto-escaping is in effect
inside the block. The block is closed with an <tt class="docutils literal"><span class="pre">endautoescape</span></tt> ending tag.</p>
<p>When auto-escaping is in effect, all variable content has HTML escaping applied
to it before placing the result into the output (but after any filters have
been applied). This is equivalent to manually applying the <a class="reference internal" href="#std:templatefilter-escape"><tt class="xref std std-tfilter docutils literal"><span class="pre">escape</span></tt></a>
filter to each variable.</p>
<p>The only exceptions are variables that are already marked as &#8220;safe&#8221; from
escaping, either by the code that populated the variable, or because it has had
the <a class="reference internal" href="#std:templatefilter-safe"><tt class="xref std std-tfilter docutils literal"><span class="pre">safe</span></tt></a> or <a class="reference internal" href="#std:templatefilter-escape"><tt class="xref std std-tfilter docutils literal"><span class="pre">escape</span></tt></a> filters applied.</p>
<p>Sample usage:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>
</div>
<div class="section" id="s-block">
<span id="s-std:templatetag-block"></span><span id="block"></span><span id="std:templatetag-block"></span><h3>block<a class="headerlink" href="#block" title="Permalink to this headline">¶</a></h3>
<p>Defines a block that can be overridden by child templates. See
<a class="reference internal" href="../../topics/templates.html#template-inheritance"><em>Template inheritance</em></a> for more information.</p>
</div>
<div class="section" id="s-comment">
<span id="s-std:templatetag-comment"></span><span id="comment"></span><span id="std:templatetag-comment"></span><h3>comment<a class="headerlink" href="#comment" title="Permalink to this headline">¶</a></h3>
<p>Ignores everything between <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">comment</span> <span class="pre">%}</span></tt> and <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">endcomment</span> <span class="pre">%}</span></tt>.
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"><div class="highlight"><pre><span class="nt">&lt;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="nt">&lt;/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="nt">&lt;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="nt">&lt;/p&gt;</span>
<span class="cp">{%</span> <span class="k">endcomment</span> <span class="cp">%}</span>
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">comment</span></tt> tags cannot be nested.</p>
</div>
<div class="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>csrf_token<a class="headerlink" href="#csrf-token" title="Permalink to this headline">¶</a></h3>
<p>This tag is used for CSRF protection, as described in the documentation for
<a class="reference internal" href="../contrib/csrf.html"><em>Cross Site Request Forgeries</em></a>.</p>
</div>
<div class="section" id="s-cycle">
<span id="s-std:templatetag-cycle"></span><span id="cycle"></span><span id="std:templatetag-cycle"></span><h3>cycle<a class="headerlink" href="#cycle" title="Permalink to this headline">¶</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"><div class="highlight"><pre><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="nt">&lt;tr</span> <span class="na">class=</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="nt">&gt;</span>
        ...
    <span class="nt">&lt;/tr&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 <tt class="docutils literal"><span class="pre">row1</span></tt>, the second to
<tt class="docutils literal"><span class="pre">row2</span></tt>, the third to <tt class="docutils literal"><span class="pre">row1</span></tt> 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,
<tt class="docutils literal"><span class="pre">rowvalue1</span></tt> and <tt class="docutils literal"><span class="pre">rowvalue2</span></tt>, you can alternate between their values like
this:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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="nt">&lt;tr</span> <span class="na">class=</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="nt">&gt;</span>
        ...
    <span class="nt">&lt;/tr&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Note that the variables included in the cycle will not be escaped. Any HTML or
Javascript code contained in the printed variable will be rendered as-is, which
could potentially lead to security issues. So either make sure that you trust
their values or use explicit escaping like this:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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="nt">&lt;tr</span> <span class="na">class=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">filter</span> <span class="nf">force_escape</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">endfilter</span> <span class="cp">%}</span><span class="s">&quot;</span><span class="nt">&gt;</span>
        ...
    <span class="nt">&lt;/tr&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"><div class="highlight"><pre><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="nt">&lt;tr</span> <span class="na">class=</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="nt">&gt;</span>
        ...
    <span class="nt">&lt;/tr&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,
just give the <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">cycle</span> <span class="pre">%}</span></tt> tag a name, using &#8220;as&#8221;, like this:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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&#8217;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
<tt class="docutils literal"><span class="pre">cycle</span></tt> tag, you can use another <tt class="docutils literal"><span class="pre">cycle</span></tt> tag and specify the name of the
variable. So, the following template:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="nt">&lt;tr&gt;</span>
    <span class="nt">&lt;td</span> <span class="na">class=</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="nt">&gt;</span>...<span class="nt">&lt;/td&gt;</span>
    <span class="nt">&lt;td</span> <span class="na">class=</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="nt">&gt;</span>...<span class="nt">&lt;/td&gt;</span>
<span class="nt">&lt;/tr&gt;</span>
<span class="nt">&lt;tr&gt;</span>
    <span class="nt">&lt;td</span> <span class="na">class=</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="nt">&gt;</span>...<span class="nt">&lt;/td&gt;</span>
    <span class="nt">&lt;td</span> <span class="na">class=</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="nt">&gt;</span>...<span class="nt">&lt;/td&gt;</span>
<span class="nt">&lt;/tr&gt;</span>
</pre></div>
</div>
<p>would output:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="nt">&lt;tr&gt;</span>
    <span class="nt">&lt;td</span> <span class="na">class=</span><span class="s">&quot;row1&quot;</span><span class="nt">&gt;</span>...<span class="nt">&lt;/td&gt;</span>
    <span class="nt">&lt;td</span> <span class="na">class=</span><span class="s">&quot;row1&quot;</span><span class="nt">&gt;</span>...<span class="nt">&lt;/td&gt;</span>
<span class="nt">&lt;/tr&gt;</span>
<span class="nt">&lt;tr&gt;</span>
    <span class="nt">&lt;td</span> <span class="na">class=</span><span class="s">&quot;row2&quot;</span><span class="nt">&gt;</span>...<span class="nt">&lt;/td&gt;</span>
    <span class="nt">&lt;td</span> <span class="na">class=</span><span class="s">&quot;row2&quot;</span><span class="nt">&gt;</span>...<span class="nt">&lt;/td&gt;</span>
<span class="nt">&lt;/tr&gt;</span>
</pre></div>
</div>
<p>You can use any number of values in a <tt class="docutils literal"><span class="pre">cycle</span></tt> tag, separated by spaces.
Values enclosed in single quotes (<tt class="docutils literal"><span class="pre">'</span></tt>) or double quotes (<tt class="docutils literal"><span class="pre">&quot;</span></tt>) are treated
as string literals, while values without quotes are treated as template
variables.</p>
<p>By default, when you use the <tt class="docutils literal"><span class="pre">as</span></tt> keyword with the cycle tag, the
usage of <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">cycle</span> <span class="pre">%}</span></tt> 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
<tt class="docutils literal"><span class="pre">silent</span></tt> keyword as the last keyword in the tag. For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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="nt">&lt;tr</span> <span class="na">class=</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="nt">&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="nt">&lt;/tr&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 <tt class="docutils literal"><span class="pre">&lt;tr&gt;</span></tt> elements with <tt class="docutils literal"><span class="pre">class</span></tt>
alternating between <tt class="docutils literal"><span class="pre">row1</span></tt> and <tt class="docutils literal"><span class="pre">row2</span></tt>. The subtemplate will have
access to <tt class="docutils literal"><span class="pre">rowcolors</span></tt> in its context and the value will match the class
of the <tt class="docutils literal"><span class="pre">&lt;tr&gt;</span></tt> that encloses it. If the <tt class="docutils literal"><span class="pre">silent</span></tt> keyword were to be
omitted, <tt class="docutils literal"><span class="pre">row1</span></tt> and <tt class="docutils literal"><span class="pre">row2</span></tt> would be emitted as normal text, outside the
<tt class="docutils literal"><span class="pre">&lt;tr&gt;</span></tt> 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 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">cycle</span> <span class="pre">%}</span></tt> doesn&#8217;t specify <tt class="docutils literal"><span class="pre">silent</span></tt>:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>For backward compatibility, the <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">cycle</span> <span class="pre">%}</span></tt> tag supports the much inferior
old syntax from previous Django versions. You shouldn&#8217;t use this in any new
projects, but for the sake of the people who are still using it, here&#8217;s what it
looks like:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">cycle</span> <span class="nv">row1</span><span class="o">,</span><span class="nv">row2</span><span class="o">,</span><span class="nv">row3</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>In this syntax, each value gets interpreted as a literal string, and there&#8217;s no
way to specify variable values. Or literal commas. Or spaces. Did we mention
you shouldn&#8217;t use this syntax in any new projects?</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.6.</span> </div>
<p>To improve safety, future versions of <tt class="docutils literal"><span class="pre">cycle</span></tt> will automatically escape
their output. You&#8217;re encouraged to activate this behavior by loading
<tt class="docutils literal"><span class="pre">cycle</span></tt> from the <tt class="docutils literal"><span class="pre">future</span></tt> template library:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">load</span> <span class="nv">cycle</span> <span class="nv">from</span> <span class="nv">future</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>When using the <tt class="docutils literal"><span class="pre">future</span></tt> version, you can disable auto-escaping with:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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="nt">&lt;tr</span> <span class="na">class=</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="nt">&gt;</span>
        ...
    <span class="nt">&lt;/tr&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
</div>
<div class="section" id="s-debug">
<span id="s-std:templatetag-debug"></span><span id="debug"></span><span id="std:templatetag-debug"></span><h3>debug<a class="headerlink" href="#debug" title="Permalink to this headline">¶</a></h3>
<p>Outputs a whole load of debugging information, including the current context
and imported modules.</p>
</div>
<div class="section" id="s-extends">
<span id="s-std:templatetag-extends"></span><span id="extends"></span><span id="std:templatetag-extends"></span><h3>extends<a class="headerlink" href="#extends" title="Permalink to this headline">¶</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><tt class="docutils literal"><span class="pre">{%</span> <span class="pre">extends</span> <span class="pre">&quot;base.html&quot;</span> <span class="pre">%}</span></tt> (with quotes) uses the literal value
<tt class="docutils literal"><span class="pre">&quot;base.html&quot;</span></tt> as the name of the parent template to extend.</li>
<li><tt class="docutils literal"><span class="pre">{%</span> <span class="pre">extends</span> <span class="pre">variable</span> <span class="pre">%}</span></tt> uses the value of <tt class="docutils literal"><span class="pre">variable</span></tt>. 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 <tt class="docutils literal"><span class="pre">Template</span></tt> object,
Django will use that object as the parent template.</li>
</ul>
<p>See <a class="reference internal" href="../../topics/templates.html#template-inheritance"><em>Template inheritance</em></a> for more information.</p>
</div>
<div class="section" id="s-filter">
<span id="s-std:templatetag-filter"></span><span id="filter"></span><span id="std:templatetag-filter"></span><h3>filter<a class="headerlink" href="#filter" title="Permalink to this headline">¶</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 <tt class="docutils literal"><span class="pre">filter</span></tt> and
<tt class="docutils literal"><span class="pre">endfilter</span></tt> tags.</p>
<p>Sample usage:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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="first admonition-title">Note</p>
<p class="last">The <a class="reference internal" href="#std:templatefilter-escape"><tt class="xref std std-tfilter docutils literal"><span class="pre">escape</span></tt></a> and <a class="reference internal" href="#std:templatefilter-safe"><tt class="xref std std-tfilter docutils literal"><span class="pre">safe</span></tt></a> filters are not acceptable
arguments. Instead, use the <a class="reference internal" href="#std:templatetag-autoescape"><tt class="xref std std-ttag docutils literal"><span class="pre">autoescape</span></tt></a> tag to manage autoescaping
for blocks of template code.</p>
</div>
</div>
<div class="section" id="s-firstof">
<span id="s-std:templatetag-firstof"></span><span id="firstof"></span><span id="std:templatetag-firstof"></span><h3>firstof<a class="headerlink" href="#firstof" title="Permalink to this headline">¶</a></h3>
<p>Outputs the first argument variable that is not False. This tag does <em>not</em>
auto-escape variable values.</p>
<p>Outputs nothing if all the passed variables are False.</p>
<p>Sample usage:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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"><div class="highlight"><pre><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="o">|</span><span class="nf">safe</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="o">|</span><span class="nf">safe</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="o">|</span><span class="nf">safe</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"><div class="highlight"><pre><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>Note that currently the variables included in the firstof tag will not be
escaped. Any HTML or Javascript code contained in the printed variable will be
rendered as-is, which could potentially lead to security issues. If you need
to escape the variables in the firstof tag, you must do so explicitly:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">filter</span> <span class="nf">force_escape</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;fallback value&quot;</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">endfilter</span> <span class="cp">%}</span>
</pre></div>
</div>
<div class="versionchanged">
<span class="title">Changed in Django 1.6:</span> <p>To improve safety, future versions of <tt class="docutils literal"><span class="pre">firstof</span></tt> will automatically escape
their output. You&#8217;re encouraged to activate this behavior by loading
<tt class="docutils literal"><span class="pre">firstof</span></tt> from the <tt class="docutils literal"><span class="pre">future</span></tt> template library:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">load</span> <span class="nv">firstof</span> <span class="nv">from</span> <span class="nv">future</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>When using the <tt class="docutils literal"><span class="pre">future</span></tt> version, you can disable auto-escaping with:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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"><div class="highlight"><pre><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>
</div>
</div>
<div class="section" id="s-for">
<span id="s-std:templatetag-for"></span><span id="for"></span><span id="std:templatetag-for"></span><h3>for<a class="headerlink" href="#for" title="Permalink to this headline">¶</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
<tt class="docutils literal"><span class="pre">athlete_list</span></tt>:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="nt">&lt;ul&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="nt">&lt;li&gt;</span><span class="cp">{{</span> <span class="nv">athlete.name</span> <span class="cp">}}</span><span class="nt">&lt;/li&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
<span class="nt">&lt;/ul&gt;</span>
</pre></div>
</div>
<p>You can loop over a list in reverse by using
<tt class="docutils literal"><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></tt>.</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 <tt class="docutils literal"><span class="pre">points</span></tt>, you could use the
following to output the list of points:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">data</span></tt>, the following
would display the keys and values of the dictionary:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>The for loop sets a number of variables available within the loop:</p>
<table class="docutils">
<colgroup>
<col width="36%" />
<col width="64%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Variable</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">forloop.counter</span></tt></td>
<td>The current iteration of the loop (1-indexed)</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">forloop.counter0</span></tt></td>
<td>The current iteration of the loop (0-indexed)</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">forloop.revcounter</span></tt></td>
<td>The number of iterations from the end of the
loop (1-indexed)</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">forloop.revcounter0</span></tt></td>
<td>The number of iterations from the end of the
loop (0-indexed)</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">forloop.first</span></tt></td>
<td>True if this is the first time through the loop</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">forloop.last</span></tt></td>
<td>True if this is the last time through the loop</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">forloop.parentloop</span></tt></td>
<td>For nested loops, this is the loop surrounding
the current one</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="s-for-empty">
<span id="for-empty"></span><h3>for ... empty<a class="headerlink" href="#for-empty" title="Permalink to this headline">¶</a></h3>
<p>The <tt class="docutils literal"><span class="pre">for</span></tt> tag can take an optional <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">empty</span> <span class="pre">%}</span></tt> clause whose text is
displayed if the given array is empty or could not be found:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="nt">&lt;ul&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="nt">&lt;li&gt;</span><span class="cp">{{</span> <span class="nv">athlete.name</span> <span class="cp">}}</span><span class="nt">&lt;/li&gt;</span>
<span class="cp">{%</span> <span class="k">empty</span> <span class="cp">%}</span>
    <span class="nt">&lt;li&gt;</span>Sorry, no athletes in this list.<span class="nt">&lt;/li&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
<span class="nt">&lt;ul&gt;</span>
</pre></div>
</div>
<p>The above is equivalent to &#8211; but shorter, cleaner, and possibly faster
than &#8211; the following:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="nt">&lt;ul&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="nt">&lt;li&gt;</span><span class="cp">{{</span> <span class="nv">athlete.name</span> <span class="cp">}}</span><span class="nt">&lt;/li&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="nt">&lt;li&gt;</span>Sorry, no athletes in this list.<span class="nt">&lt;/li&gt;</span>
  <span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
<span class="nt">&lt;/ul&gt;</span>
</pre></div>
</div>
</div>
<div class="section" id="s-if">
<span id="s-std:templatetag-if"></span><span id="if"></span><span id="std:templatetag-if"></span><h3>if<a class="headerlink" href="#if" title="Permalink to this headline">¶</a></h3>
<p>The <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">if</span> <span class="pre">%}</span></tt> tag evaluates a variable, and if that variable is &#8220;true&#8221; (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"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">athlete_list</span></tt> is not empty, the number of athletes will be
displayed by the <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">athlete_list|length</span> <span class="pre">}}</span></tt> variable.</p>
<p>As you can see, the <tt class="docutils literal"><span class="pre">if</span></tt> tag may take one or several <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">elif</span> <span class="pre">%}</span></tt>
clauses, as well as an <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">else</span> <span class="pre">%}</span></tt> clause that will be displayed if all
previous conditions fail. These clauses are optional.</p>
</div>
<div class="section" id="s-boolean-operators">
<span id="boolean-operators"></span><h3>Boolean operators<a class="headerlink" href="#boolean-operators" title="Permalink to this headline">¶</a></h3>
<p><a class="reference internal" href="#std:templatetag-if"><tt class="xref std std-ttag docutils literal"><span class="pre">if</span></tt></a> tags may use <tt class="docutils literal"><span class="pre">and</span></tt>, <tt class="docutils literal"><span class="pre">or</span></tt> or <tt class="docutils literal"><span class="pre">not</span></tt> to test a number of
variables or to negate a given variable:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 (OK, so
    writing English translations of boolean logic sounds
    stupid; it&#39;s not our fault).
<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 <tt class="docutils literal"><span class="pre">and</span></tt> and <tt class="docutils literal"><span class="pre">or</span></tt> clauses within the same tag is allowed, with
<tt class="docutils literal"><span class="pre">and</span></tt> having higher precedence than <tt class="docutils literal"><span class="pre">or</span></tt> e.g.:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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-python"><div class="highlight"><pre><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>
</pre></div>
</div>
<p>Use of actual parentheses in the <a class="reference internal" href="#std:templatetag-if"><tt class="xref std std-ttag docutils literal"><span class="pre">if</span></tt></a> tag is invalid syntax. If you need
them to indicate precedence, you should use nested <a class="reference internal" href="#std:templatetag-if"><tt class="xref std std-ttag docutils literal"><span class="pre">if</span></tt></a> tags.</p>
<p><a class="reference internal" href="#std:templatetag-if"><tt class="xref std std-ttag docutils literal"><span class="pre">if</span></tt></a> tags may also use the operators <tt class="docutils literal"><span class="pre">==</span></tt>, <tt class="docutils literal"><span class="pre">!=</span></tt>, <tt class="docutils literal"><span class="pre">&lt;</span></tt>, <tt class="docutils literal"><span class="pre">&gt;</span></tt>,
<tt class="docutils literal"><span class="pre">&lt;=</span></tt>, <tt class="docutils literal"><span class="pre">&gt;=</span></tt> and <tt class="docutils literal"><span class="pre">in</span></tt> which work as follows:</p>
</div>
<div class="section" id="s-operator">
<span id="operator"></span><h3><tt class="docutils literal"><span class="pre">==</span></tt> operator<a class="headerlink" href="#operator" title="Permalink to this headline">¶</a></h3>
<p>Equality. Example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>
</div>
<div class="section" id="s-id1">
<span id="id1"></span><h3><tt class="docutils literal"><span class="pre">!=</span></tt> operator<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<p>Inequality. Example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">if</span> <span class="nv">somevar</span> <span class="p">!</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>
</div>
<div class="section" id="s-id2">
<span id="id2"></span><h3><tt class="docutils literal"><span class="pre">&lt;</span></tt> operator<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
<p>Less than. Example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>
</div>
<div class="section" id="s-id3">
<span id="id3"></span><h3><tt class="docutils literal"><span class="pre">&gt;</span></tt> operator<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h3>
<p>Greater than. Example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>
</div>
<div class="section" id="s-id4">
<span id="id4"></span><h3><tt class="docutils literal"><span class="pre">&lt;=</span></tt> operator<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h3>
<p>Less than or equal to. Example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>
</div>
<div class="section" id="s-id5">
<span id="id5"></span><h3><tt class="docutils literal"><span class="pre">&gt;=</span></tt> operator<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h3>
<p>Greater than or equal to. Example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>
</div>
<div class="section" id="s-in-operator">
<span id="in-operator"></span><h3><tt class="docutils literal"><span class="pre">in</span></tt> operator<a class="headerlink" href="#in-operator" title="Permalink to this headline">¶</a></h3>
<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 <tt class="docutils literal"><span class="pre">x</span> <span class="pre">in</span> <span class="pre">y</span></tt> will be interpreted:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>
</div>
<div class="section" id="s-not-in-operator">
<span id="not-in-operator"></span><h3><tt class="docutils literal"><span class="pre">not</span> <span class="pre">in</span></tt> operator<a class="headerlink" href="#not-in-operator" title="Permalink to this headline">¶</a></h3>
<p>Not contained within. This is the negation of the <tt class="docutils literal"><span class="pre">in</span></tt> operator.</p>
<p>The comparison operators cannot be &#8216;chained&#8217; like in Python or in mathematical
notation. For example, instead of using:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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"><div class="highlight"><pre><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>
</div>
<div class="section" id="s-filters">
<span id="filters"></span><h3>Filters<a class="headerlink" href="#filters" title="Permalink to this headline">¶</a></h3>
<p>You can also use filters in the <a class="reference internal" href="#std:templatetag-if"><tt class="xref std std-ttag docutils literal"><span class="pre">if</span></tt></a> expression. For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>
</div>
<div class="section" id="s-complex-expressions">
<span id="complex-expressions"></span><h3>Complex expressions<a class="headerlink" href="#complex-expressions" title="Permalink to this headline">¶</a></h3>
<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><tt class="docutils literal"><span class="pre">or</span></tt></li>
<li><tt class="docutils literal"><span class="pre">and</span></tt></li>
<li><tt class="docutils literal"><span class="pre">not</span></tt></li>
<li><tt class="docutils literal"><span class="pre">in</span></tt></li>
<li><tt class="docutils literal"><span class="pre">==</span></tt>, <tt class="docutils literal"><span class="pre">!=</span></tt>, <tt class="docutils literal"><span class="pre">&lt;</span></tt>, <tt class="docutils literal"><span class="pre">&gt;</span></tt>, <tt class="docutils literal"><span class="pre">&lt;=</span></tt>, <tt class="docutils literal"><span class="pre">&gt;=</span></tt></li>
</ul>
<p>(This follows Python exactly). So, for example, the following complex
<a class="reference internal" href="#std:templatetag-if"><tt class="xref std std-ttag docutils literal"><span class="pre">if</span></tt></a> tag:</p>
<div class="highlight-django"><div class="highlight"><pre><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><span class="x"></span>
</pre></div>
</div>
<p>...will be interpreted as:</p>
<div class="highlight-python"><div class="highlight"><pre><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"><tt class="xref std std-ttag docutils literal"><span class="pre">if</span></tt></a> tags.
Sometimes that is better for clarity anyway, for the sake of those who do not
know the precedence rules.</p>
</div>
<div class="section" id="s-ifchanged">
<span id="s-std:templatetag-ifchanged"></span><span id="ifchanged"></span><span id="std:templatetag-ifchanged"></span><h3>ifchanged<a class="headerlink" href="#ifchanged" title="Permalink to this headline">¶</a></h3>
<p>Check if a value has changed from the last iteration of a loop.</p>
<p>The <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">ifchanged</span> <span class="pre">%}</span></tt> block tag is used within a loop. It has two possible
uses.</p>
<ol class="arabic">
<li><p class="first">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"><div class="highlight"><pre><span class="nt">&lt;h1&gt;</span>Archive for <span class="cp">{{</span> <span class="nv">year</span> <span class="cp">}}</span><span class="nt">&lt;/h1&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="nt">&lt;h3&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="nt">&lt;/h3&gt;</span><span class="cp">{%</span> <span class="k">endifchanged</span> <span class="cp">%}</span>
    <span class="nt">&lt;a</span> <span class="na">href=</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="nt">&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="nt">&lt;/a&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
</li>
<li><p class="first">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"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">ifchanged</span></tt> tag can also take an optional <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">else</span> <span class="pre">%}</span></tt> clause that
will be displayed if the value has not changed:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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="nt">&lt;div</span> <span class="na">style=</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="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="s">        </span><span class="cp">{%</span> <span class="k">else</span> <span class="cp">%}</span><span class="s"></span>
<span class="s">            grey</span>
<span class="s">        </span><span class="cp">{%</span> <span class="k">endifchanged</span> <span class="cp">%}</span><span class="s"></span>
<span class="s">    &quot;</span><span class="nt">&gt;</span><span class="cp">{{</span> <span class="nv">match</span> <span class="cp">}}</span><span class="nt">&lt;/div&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
</pre></div>
</div>
</div>
<div class="section" id="s-ifequal">
<span id="s-std:templatetag-ifequal"></span><span id="ifequal"></span><span id="std:templatetag-ifequal"></span><h3>ifequal<a class="headerlink" href="#ifequal" title="Permalink to this headline">¶</a></h3>
<p>Output the contents of the block if the two arguments equal each other.</p>
<p>Example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">ifequal</span> <span class="nv">user.pk</span> <span class="nv">comment.user_id</span> <span class="cp">%}</span>
    ...
<span class="cp">{%</span> <span class="k">endifequal</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>As in the <a class="reference internal" href="#std:templatetag-if"><tt class="xref std std-ttag docutils literal"><span class="pre">if</span></tt></a> tag, an <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">else</span> <span class="pre">%}</span></tt> clause is optional.</p>
<p>The arguments can be hard-coded strings, so the following is valid:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">ifequal</span> <span class="nv">user.username</span> <span class="s2">&quot;adrian&quot;</span> <span class="cp">%}</span>
    ...
<span class="cp">{%</span> <span class="k">endifequal</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>An alternative to the <tt class="docutils literal"><span class="pre">ifequal</span></tt> tag is to use the <a class="reference internal" href="#std:templatetag-if"><tt class="xref std std-ttag docutils literal"><span class="pre">if</span></tt></a> tag and the
<tt class="docutils literal"><span class="pre">==</span></tt> operator.</p>
</div>
<div class="section" id="s-ifnotequal">
<span id="s-std:templatetag-ifnotequal"></span><span id="ifnotequal"></span><span id="std:templatetag-ifnotequal"></span><h3>ifnotequal<a class="headerlink" href="#ifnotequal" title="Permalink to this headline">¶</a></h3>
<p>Just like <a class="reference internal" href="#std:templatetag-ifequal"><tt class="xref std std-ttag docutils literal"><span class="pre">ifequal</span></tt></a>, except it tests that the two arguments are not
equal.</p>
<p>An alternative to the <tt class="docutils literal"><span class="pre">ifnotequal</span></tt> tag is to use the <a class="reference internal" href="#std:templatetag-if"><tt class="xref std std-ttag docutils literal"><span class="pre">if</span></tt></a> tag and
the <tt class="docutils literal"><span class="pre">!=</span></tt> operator.</p>
</div>
<div class="section" id="s-include">
<span id="s-std:templatetag-include"></span><span id="include"></span><span id="std:templatetag-include"></span><h3>include<a class="headerlink" href="#include" title="Permalink to this headline">¶</a></h3>
<p>Loads a template and renders it with the current context. This is a way of
&#8220;including&#8221; other templates within a template.</p>
<p>The template name can either be a variable or a hard-coded (quoted) string,
in either single or double quotes.</p>
<p>This example includes the contents of the template <tt class="docutils literal"><span class="pre">&quot;foo/bar.html&quot;</span></tt>:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>This example includes the contents of the template whose name is contained in
the variable <tt class="docutils literal"><span class="pre">template_name</span></tt>:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">include</span> <span class="nv">template_name</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>An included template is rendered within the context of the template that
includes it. This example produces the output <tt class="docutils literal"><span class="pre">&quot;Hello,</span> <span class="pre">John&quot;</span></tt>:</p>
<ul>
<li><p class="first">Context: variable <tt class="docutils literal"><span class="pre">person</span></tt> is set to <tt class="docutils literal"><span class="pre">&quot;john&quot;</span></tt>.</p>
</li>
<li><p class="first">Template:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 class="first">The <tt class="docutils literal"><span class="pre">name_snippet.html</span></tt> template:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">only</span></tt> option. No other variables are
available to the included template:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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="first admonition-title">Note</p>
<p class="last">The <a class="reference internal" href="#std:templatetag-include"><tt class="xref std std-ttag docutils literal"><span class="pre">include</span></tt></a> tag should be considered as an implementation of
&#8220;render this subtemplate and include the HTML&#8221;, not as &#8220;parse this
subtemplate and include its contents as if it were part of the parent&#8221;.
This means that there is no shared state between included templates &#8211;
each include is a completely independent rendering process.</p>
</div>
<p>See also: <a class="reference internal" href="#std:templatetag-ssi"><tt class="xref std std-ttag docutils literal"><span class="pre">{%</span> <span class="pre">ssi</span> <span class="pre">%}</span></tt></a>.</p>
</div>
<div class="section" id="s-load">
<span id="s-std:templatetag-load"></span><span id="load"></span><span id="std:templatetag-load"></span><h3>load<a class="headerlink" href="#load" title="Permalink to this headline">¶</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 <tt class="docutils literal"><span class="pre">somelibrary</span></tt> and <tt class="docutils literal"><span class="pre">otherlibrary</span></tt> located in package
<tt class="docutils literal"><span class="pre">package</span></tt>:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">from</span></tt> argument. In this example, the template tags/filters named <tt class="docutils literal"><span class="pre">foo</span></tt>
and <tt class="docutils literal"><span class="pre">bar</span></tt> will be loaded from <tt class="docutils literal"><span class="pre">somelibrary</span></tt>:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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"><em>Custom tag and filter libraries</em></a> for
more information.</p>
</div>
<div class="section" id="s-now">
<span id="s-std:templatetag-now"></span><span id="now"></span><span id="std:templatetag-now"></span><h3>now<a class="headerlink" href="#now" title="Permalink to this headline">¶</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"><tt class="xref std std-tfilter docutils literal"><span class="pre">date</span></tt></a> filter section.</p>
<p>Example:</p>
<div class="highlight-html+django"><div class="highlight"><pre>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
&#8220;raw&#8221; value. In this example, &#8220;f&#8221; is backslash-escaped, because otherwise
&#8220;f&#8221; is a format string that displays the time. The &#8220;o&#8221; doesn&#8217;t need to be
escaped, because it&#8217;s not a format character:</p>
<div class="highlight-html+django"><div class="highlight"><pre>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 &#8220;It is the 4th of September&#8221;.</p>
<div class="admonition note">
<p class="first 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"><tt class="xref std std-setting docutils literal"><span class="pre">DATE_FORMAT</span></tt></a>, <a class="reference internal" href="../settings.html#std:setting-DATETIME_FORMAT"><tt class="xref std std-setting docutils literal"><span class="pre">DATETIME_FORMAT</span></tt></a>,
<a class="reference internal" href="../settings.html#std:setting-SHORT_DATE_FORMAT"><tt class="xref std std-setting docutils literal"><span class="pre">SHORT_DATE_FORMAT</span></tt></a> or <a class="reference internal" href="../settings.html#std:setting-SHORT_DATETIME_FORMAT"><tt class="xref std std-setting docutils literal"><span class="pre">SHORT_DATETIME_FORMAT</span></tt></a>.
The predefined formats may vary depending on the current locale and
if <a class="reference internal" href="../../topics/i18n/formatting.html#format-localization"><em>Format localization</em></a> is enabled, e.g.:</p>
<div class="last highlight-html+django"><div class="highlight"><pre>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>
</div>
<div class="section" id="s-regroup">
<span id="s-std:templatetag-regroup"></span><span id="regroup"></span><span id="std:templatetag-regroup"></span><h3>regroup<a class="headerlink" href="#regroup" title="Permalink to this headline">¶</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 &#8220;places&#8221; is a list of cities represented by dictionaries containing <tt class="docutils literal"><span class="pre">&quot;name&quot;</span></tt>, <tt class="docutils literal"><span class="pre">&quot;population&quot;</span></tt>, and <tt class="docutils literal"><span class="pre">&quot;country&quot;</span></tt> keys:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">cities</span> <span class="o">=</span> <span class="p">[</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;Mumbai&#39;</span><span class="p">,</span> <span class="s">&#39;population&#39;</span><span class="p">:</span> <span class="s">&#39;19,000,000&#39;</span><span class="p">,</span> <span class="s">&#39;country&#39;</span><span class="p">:</span> <span class="s">&#39;India&#39;</span><span class="p">},</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;Calcutta&#39;</span><span class="p">,</span> <span class="s">&#39;population&#39;</span><span class="p">:</span> <span class="s">&#39;15,000,000&#39;</span><span class="p">,</span> <span class="s">&#39;country&#39;</span><span class="p">:</span> <span class="s">&#39;India&#39;</span><span class="p">},</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;New York&#39;</span><span class="p">,</span> <span class="s">&#39;population&#39;</span><span class="p">:</span> <span class="s">&#39;20,000,000&#39;</span><span class="p">,</span> <span class="s">&#39;country&#39;</span><span class="p">:</span> <span class="s">&#39;USA&#39;</span><span class="p">},</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;Chicago&#39;</span><span class="p">,</span> <span class="s">&#39;population&#39;</span><span class="p">:</span> <span class="s">&#39;7,000,000&#39;</span><span class="p">,</span> <span class="s">&#39;country&#39;</span><span class="p">:</span> <span class="s">&#39;USA&#39;</span><span class="p">},</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;Tokyo&#39;</span><span class="p">,</span> <span class="s">&#39;population&#39;</span><span class="p">:</span> <span class="s">&#39;33,000,000&#39;</span><span class="p">,</span> <span class="s">&#39;country&#39;</span><span class="p">:</span> <span class="s">&#39;Japan&#39;</span><span class="p">},</span>
<span class="p">]</span>
</pre></div>
</div>
<p>...and you&#8217;d like to display a hierarchical list that is ordered by country, like this:</p>
<ul>
<li><dl class="first docutils">
<dt>India</dt>
<dd><ul class="first last simple">
<li>Mumbai: 19,000,000</li>
<li>Calcutta: 15,000,000</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>USA</dt>
<dd><ul class="first last simple">
<li>New York: 20,000,000</li>
<li>Chicago: 7,000,000</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>Japan</dt>
<dd><ul class="first last simple">
<li>Tokyo: 33,000,000</li>
</ul>
</dd>
</dl>
</li>
</ul>
<p>You can use the <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">regroup</span> <span class="pre">%}</span></tt> tag to group the list of cities by country.
The following snippet of template code would accomplish this:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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="nt">&lt;ul&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="nt">&lt;li&gt;</span><span class="cp">{{</span> <span class="nv">country.grouper</span> <span class="cp">}}</span>
    <span class="nt">&lt;ul&gt;</span>
        <span class="cp">{%</span> <span class="k">for</span> <span class="nv">item</span> <span class="k">in</span> <span class="nv">country.list</span> <span class="cp">%}</span>
          <span class="nt">&lt;li&gt;</span><span class="cp">{{</span> <span class="nv">item.name</span> <span class="cp">}}</span>: <span class="cp">{{</span> <span class="nv">item.population</span> <span class="cp">}}</span><span class="nt">&lt;/li&gt;</span>
        <span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
    <span class="nt">&lt;/ul&gt;</span>
    <span class="nt">&lt;/li&gt;</span>
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
<span class="nt">&lt;/ul&gt;</span>
</pre></div>
</div>
<p>Let&#8217;s walk through this example. <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">regroup</span> <span class="pre">%}</span></tt> takes three arguments: the
list you want to regroup, the attribute to group by, and the name of the
resulting list. Here, we&#8217;re regrouping the <tt class="docutils literal"><span class="pre">cities</span></tt> list by the <tt class="docutils literal"><span class="pre">country</span></tt>
attribute and calling the result <tt class="docutils literal"><span class="pre">country_list</span></tt>.</p>
<p><tt class="docutils literal"><span class="pre">{%</span> <span class="pre">regroup</span> <span class="pre">%}</span></tt> produces a list (in this case, <tt class="docutils literal"><span class="pre">country_list</span></tt>) of
<strong>group objects</strong>. Each group object has two attributes:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">grouper</span></tt> &#8211; the item that was grouped by (e.g., the string &#8220;India&#8221; or
&#8220;Japan&#8221;).</li>
<li><tt class="docutils literal"><span class="pre">list</span></tt> &#8211; a list of all items in this group (e.g., a list of all cities
with country=&#8217;India&#8217;).</li>
</ul>
<p>Note that <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">regroup</span> <span class="pre">%}</span></tt> does not order its input! Our example relies on
the fact that the <tt class="docutils literal"><span class="pre">cities</span></tt> list was ordered by <tt class="docutils literal"><span class="pre">country</span></tt> in the first place.
If the <tt class="docutils literal"><span class="pre">cities</span></tt> list did <em>not</em> order its members by <tt class="docutils literal"><span class="pre">country</span></tt>, the
regrouping would naively display more than one group for a single country. For
example, say the <tt class="docutils literal"><span class="pre">cities</span></tt> list was set to this (note that the countries are not
grouped together):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">cities</span> <span class="o">=</span> <span class="p">[</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;Mumbai&#39;</span><span class="p">,</span> <span class="s">&#39;population&#39;</span><span class="p">:</span> <span class="s">&#39;19,000,000&#39;</span><span class="p">,</span> <span class="s">&#39;country&#39;</span><span class="p">:</span> <span class="s">&#39;India&#39;</span><span class="p">},</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;New York&#39;</span><span class="p">,</span> <span class="s">&#39;population&#39;</span><span class="p">:</span> <span class="s">&#39;20,000,000&#39;</span><span class="p">,</span> <span class="s">&#39;country&#39;</span><span class="p">:</span> <span class="s">&#39;USA&#39;</span><span class="p">},</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;Calcutta&#39;</span><span class="p">,</span> <span class="s">&#39;population&#39;</span><span class="p">:</span> <span class="s">&#39;15,000,000&#39;</span><span class="p">,</span> <span class="s">&#39;country&#39;</span><span class="p">:</span> <span class="s">&#39;India&#39;</span><span class="p">},</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;Chicago&#39;</span><span class="p">,</span> <span class="s">&#39;population&#39;</span><span class="p">:</span> <span class="s">&#39;7,000,000&#39;</span><span class="p">,</span> <span class="s">&#39;country&#39;</span><span class="p">:</span> <span class="s">&#39;USA&#39;</span><span class="p">},</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;Tokyo&#39;</span><span class="p">,</span> <span class="s">&#39;population&#39;</span><span class="p">:</span> <span class="s">&#39;33,000,000&#39;</span><span class="p">,</span> <span class="s">&#39;country&#39;</span><span class="p">:</span> <span class="s">&#39;Japan&#39;</span><span class="p">},</span>
<span class="p">]</span>
</pre></div>
</div>
<p>With this input for <tt class="docutils literal"><span class="pre">cities</span></tt>, the example <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">regroup</span> <span class="pre">%}</span></tt> template code
above would result in the following output:</p>
<ul>
<li><dl class="first docutils">
<dt>India</dt>
<dd><ul class="first last simple">
<li>Mumbai: 19,000,000</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>USA</dt>
<dd><ul class="first last simple">
<li>New York: 20,000,000</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>India</dt>
<dd><ul class="first last simple">
<li>Calcutta: 15,000,000</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>USA</dt>
<dd><ul class="first last simple">
<li>Chicago: 7,000,000</li>
</ul>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>Japan</dt>
<dd><ul class="first last simple">
<li>Tokyo: 33,000,000</li>
</ul>
</dd>
</dl>
</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"><tt class="xref std std-tfilter docutils literal"><span class="pre">dictsort</span></tt></a> filter, if your data is in a list of dictionaries:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>
</div>
<div class="section" id="s-grouping-on-other-properties">
<span id="grouping-on-other-properties"></span><h3>Grouping on other properties<a class="headerlink" href="#grouping-on-other-properties" title="Permalink to this headline">¶</a></h3>
<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 &#8220;country&#8221; field is a foreign key to a class with
an attribute &#8220;description,&#8221; you could use:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">country</span></tt> is a field with <tt class="docutils literal"><span class="pre">choices</span></tt>, 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"><tt class="xref py py-meth docutils literal"><span class="pre">get_FOO_display()</span></tt></a> method available as an
attribute, allowing  you to group on the display string rather than the
<tt class="docutils literal"><span class="pre">choices</span></tt> key:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">country.grouper</span> <span class="pre">}}</span></tt> will now display the value fields from the
<tt class="docutils literal"><span class="pre">choices</span></tt> set rather than the keys.</p>
</div>
<div class="section" id="s-spaceless">
<span id="s-std:templatetag-spaceless"></span><span id="spaceless"></span><span id="std:templatetag-spaceless"></span><h3>spaceless<a class="headerlink" href="#spaceless" title="Permalink to this headline">¶</a></h3>
<p>Removes whitespace between HTML tags. This includes tab
characters and newlines.</p>
<p>Example usage:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">spaceless</span> <span class="cp">%}</span>
    <span class="nt">&lt;p&gt;</span>
        <span class="nt">&lt;a</span> <span class="na">href=</span><span class="s">&quot;foo/&quot;</span><span class="nt">&gt;</span>Foo<span class="nt">&lt;/a&gt;</span>
    <span class="nt">&lt;/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"><div class="highlight"><pre><span class="nt">&lt;p&gt;&lt;a</span> <span class="na">href=</span><span class="s">&quot;foo/&quot;</span><span class="nt">&gt;</span>Foo<span class="nt">&lt;/a&gt;&lt;/p&gt;</span>
</pre></div>
</div>
<p>Only space between <em>tags</em> is removed &#8211; not space between tags and text. In
this example, the space around <tt class="docutils literal"><span class="pre">Hello</span></tt> won&#8217;t be stripped:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">spaceless</span> <span class="cp">%}</span>
    <span class="nt">&lt;strong&gt;</span>
        Hello
    <span class="nt">&lt;/strong&gt;</span>
<span class="cp">{%</span> <span class="k">endspaceless</span> <span class="cp">%}</span>
</pre></div>
</div>
</div>
<div class="section" id="s-ssi">
<span id="s-std:templatetag-ssi"></span><span id="ssi"></span><span id="std:templatetag-ssi"></span><h3>ssi<a class="headerlink" href="#ssi" title="Permalink to this headline">¶</a></h3>
<p>Outputs the contents of a given file into the page.</p>
<p>Like a simple <a class="reference internal" href="#std:templatetag-include"><tt class="xref std std-ttag docutils literal"><span class="pre">include</span></tt></a> tag, <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">ssi</span> <span class="pre">%}</span></tt> includes the contents of
another file &#8211; which must be specified using an absolute path &#8211; in the
current page:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">ssi</span> <span class="s1">&#39;/home/html/ljworld.com/includes/right_generic.html&#39;</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>The first parameter of <tt class="docutils literal"><span class="pre">ssi</span></tt> can be a quoted literal or any other context
variable.</p>
<p>If the optional <tt class="docutils literal"><span class="pre">parsed</span></tt> parameter is given, the contents of the included
file are evaluated as template code, within the current context:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">ssi</span> <span class="s1">&#39;/home/html/ljworld.com/includes/right_generic.html&#39;</span> <span class="nv">parsed</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Note that if you use <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">ssi</span> <span class="pre">%}</span></tt>, you&#8217;ll need to define
<a class="reference internal" href="../settings.html#std:setting-ALLOWED_INCLUDE_ROOTS"><tt class="xref std std-setting docutils literal"><span class="pre">ALLOWED_INCLUDE_ROOTS</span></tt></a> in your Django settings, as a security
measure.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">With the <a class="reference internal" href="#std:templatetag-ssi"><tt class="xref std std-ttag docutils literal"><span class="pre">ssi</span></tt></a> tag and the <tt class="docutils literal"><span class="pre">parsed</span></tt> parameter
there is no shared state between files &#8211; each include is a completely
independent rendering process. This means it&#8217;s not possible for example to
define blocks or alter the context in the current page using the included
file.</p>
</div>
<p>See also: <a class="reference internal" href="#std:templatetag-include"><tt class="xref std std-ttag docutils literal"><span class="pre">{%</span> <span class="pre">include</span> <span class="pre">%}</span></tt></a>.</p>
</div>
<div class="section" id="s-templatetag">
<span id="s-std:templatetag-templatetag"></span><span id="templatetag"></span><span id="std:templatetag-templatetag"></span><h3>templatetag<a class="headerlink" href="#templatetag" title="Permalink to this headline">¶</a></h3>
<p>Outputs one of the syntax characters used to compose template tags.</p>
<p>Since the template system has no concept of &#8220;escaping&#8221;, to display one of the
bits used in template tags, you must use the <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">templatetag</span> <span class="pre">%}</span></tt> tag.</p>
<p>The argument tells which template bit to output:</p>
<table class="docutils">
<colgroup>
<col width="72%" />
<col width="28%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Argument</th>
<th class="head">Outputs</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">openblock</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{%</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">closeblock</span></tt></td>
<td><tt class="docutils literal"><span class="pre">%}</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">openvariable</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{{</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">closevariable</span></tt></td>
<td><tt class="docutils literal"><span class="pre">}}</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">openbrace</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">closebrace</span></tt></td>
<td><tt class="docutils literal"><span class="pre">}</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">opencomment</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{#</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">closecomment</span></tt></td>
<td><tt class="docutils literal"><span class="pre">#}</span></tt></td>
</tr>
</tbody>
</table>
<p>Sample usage:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">templatetag</span> <span class="nv">openblock</span> <span class="cp">%}</span> url &#39;entry_list&#39; <span class="cp">{%</span> <span class="k">templatetag</span> <span class="nv">closeblock</span> <span class="cp">%}</span>
</pre></div>
</div>
</div>
<div class="section" id="s-url">
<span id="s-std:templatetag-url"></span><span id="url"></span><span id="std:templatetag-url"></span><h3>url<a class="headerlink" href="#url" title="Permalink to this headline">¶</a></h3>
<p>Returns an absolute path reference (a URL without the domain name) matching a
given view function and optional parameters.</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.6:</span> 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"><tt class="xref py py-func docutils literal"><span class="pre">iri_to_uri()</span></tt></a>.</div>
<p>This is a way to output links without violating the DRY principle by having to
hard-code URLs in your templates:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">url</span> <span class="s1">&#39;path.to.some_view&#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 path to a view function in the format
<tt class="docutils literal"><span class="pre">package.package.module.function</span></tt>. 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"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">url</span> <span class="s1">&#39;path.to.some_view&#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, <tt class="docutils literal"><span class="pre">app_views.client</span></tt>, whose URLconf
takes a client ID (here, <tt class="docutils literal"><span class="pre">client()</span></tt> is a method inside the views file
<tt class="docutils literal"><span class="pre">app_views.py</span></tt>). The URLconf line might look like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">(</span><span class="s">&#39;^client/(\d+)/$&#39;</span><span class="p">,</span> <span class="s">&#39;app_views.client&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>If this app&#8217;s URLconf is included into the project&#8217;s URLconf under a path
such as this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">(</span><span class="s">&#39;^clients/&#39;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s">&#39;project_name.app_name.urls&#39;</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"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">/clients/client/123/</span></tt>.</p>
<p>If you&#8217;re using <a class="reference internal" href="../../topics/http/urls.html#naming-url-patterns"><em>named URL patterns</em></a>, you can
refer to the name of the pattern in the <tt class="docutils literal"><span class="pre">url</span></tt> tag instead of using the
path to the view.</p>
<p>Note that if the URL you&#8217;re reversing doesn&#8217;t exist, you&#8217;ll get an
<a class="reference internal" href="../exceptions.html#django.core.urlresolvers.NoReverseMatch" title="django.core.urlresolvers.NoReverseMatch"><tt class="xref py py-exc docutils literal"><span class="pre">NoReverseMatch</span></tt></a> exception raised, which will
cause your site to display an error page.</p>
<p>If you&#8217;d like to retrieve a URL without displaying it, you can use a slightly
different call:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">url</span> <span class="s1">&#39;path.to.view&#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="nt">&lt;a</span> <span class="na">href=</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="nt">&gt;</span>I&#39;m linking to <span class="cp">{{</span> <span class="nv">the_url</span> <span class="cp">}}</span><span class="nt">&lt;/a&gt;</span>
</pre></div>
</div>
<p>The scope of the variable created by the  <tt class="docutils literal"><span class="pre">as</span> <span class="pre">var</span></tt> syntax is the
<tt class="docutils literal"><span class="pre">{%</span> <span class="pre">block</span> <span class="pre">%}</span></tt> in which the <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">url</span> <span class="pre">%}</span></tt> tag appears.</p>
<p>This <tt class="docutils literal"><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></tt> syntax will <em>not</em> cause an error if the view is
missing. In practice you&#8217;ll use this to link to views that are optional:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">url</span> <span class="s1">&#39;path.to.view&#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="nt">&lt;a</span> <span class="na">href=</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="nt">&gt;</span>Link to optional stuff<span class="nt">&lt;/a&gt;</span>
<span class="cp">{%</span> <span class="k">endif</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>If you&#8217;d like to retrieve a namespaced URL, specify the fully qualified name:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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"><em>namespaced URL resolution strategy</em></a>, including using any hints provided
by the context as to the current application.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p>Don&#8217;t forget to put quotes around the function path or pattern name!</p>
<div class="last versionchanged">
<span class="title">Changed in Django 1.5:</span> The first parameter used not to be quoted, which was inconsistent with
other template tags. Since Django 1.5, it is evaluated according to
the usual rules: it can be a quoted string or a variable that will be
looked up in the context.</div>
</div>
</div>
<div class="section" id="s-verbatim">
<span id="s-std:templatetag-verbatim"></span><span id="verbatim"></span><span id="std:templatetag-verbatim"></span><h3>verbatim<a class="headerlink" href="#verbatim" title="Permalink to this headline">¶</a></h3>
<div class="versionadded">
<span class="title">New in Django 1.5.</span> </div>
<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&#8217;s syntax. For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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
<tt class="docutils literal"><span class="pre">{%</span> <span class="pre">endverbatim</span> <span class="pre">%}</span></tt> as part of the unrendered contents:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>
</div>
<div class="section" id="s-widthratio">
<span id="s-std:templatetag-widthratio"></span><span id="widthratio"></span><span id="std:templatetag-widthratio"></span><h3>widthratio<a class="headerlink" href="#widthratio" title="Permalink to this headline">¶</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"><div class="highlight"><pre><span class="nt">&lt;img</span> <span class="na">src=</span><span class="s">&quot;bar.png&quot;</span> <span class="na">alt=</span><span class="s">&quot;Bar&quot;</span>
     <span class="na">height=</span><span class="s">&quot;10&quot;</span> <span class="na">width=</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="nt">/&gt;</span>
</pre></div>
</div>
<p>If <tt class="docutils literal"><span class="pre">this_value</span></tt> is 175, <tt class="docutils literal"><span class="pre">max_value</span></tt> is 200, and <tt class="docutils literal"><span class="pre">max_width</span></tt> 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>
</div>
<div class="section" id="s-with">
<span id="s-std:templatetag-with"></span><span id="with"></span><span id="std:templatetag-with"></span><h3>with<a class="headerlink" href="#with" title="Permalink to this headline">¶</a></h3>
<p>Caches a complex variable under a simpler name. This is useful when accessing
an &#8220;expensive&#8221; method (e.g., one that hits the database) multiple times.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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, <tt class="docutils literal"><span class="pre">total</span></tt>) is only available
between the <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">with</span> <span class="pre">%}</span></tt> and <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">endwith</span> <span class="pre">%}</span></tt> tags.</p>
<p>You can assign more than one context variable:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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="first admonition-title">Note</p>
<p class="last">The previous more verbose format is still supported:
<tt class="docutils literal"><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></tt></p>
</div>
</div>
</div>
<div class="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="Permalink to this headline">¶</a></h2>
<div class="section" id="s-add">
<span id="s-std:templatefilter-add"></span><span id="add"></span><span id="std:templatefilter-add"></span><h3>add<a class="headerlink" href="#add" title="Permalink to this headline">¶</a></h3>
<p>Adds the argument to the value.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">4</span></tt>, then the output will be <tt class="docutils literal"><span class="pre">6</span></tt>.</p>
<p>This filter will first try to coerce both values to integers. If this fails,
it&#8217;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"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">first</span></tt> is <tt class="docutils literal"><span class="pre">[1,</span> <span class="pre">2,</span> <span class="pre">3]</span></tt> and <tt class="docutils literal"><span class="pre">second</span></tt> is <tt class="docutils literal"><span class="pre">[4,</span> <span class="pre">5,</span> <span class="pre">6]</span></tt>, then the
output will be <tt class="docutils literal"><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></tt>.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">Strings that can be coerced to integers will be <strong>summed</strong>, not
concatenated, as in the first example above.</p>
</div>
</div>
<div class="section" id="s-addslashes">
<span id="s-std:templatefilter-addslashes"></span><span id="addslashes"></span><span id="std:templatefilter-addslashes"></span><h3>addslashes<a class="headerlink" href="#addslashes" title="Permalink to this headline">¶</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"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;I'm</span> <span class="pre">using</span> <span class="pre">Django&quot;</span></tt>, the output will be
<tt class="docutils literal"><span class="pre">&quot;I\'m</span> <span class="pre">using</span> <span class="pre">Django&quot;</span></tt>.</p>
</div>
<div class="section" id="s-capfirst">
<span id="s-std:templatefilter-capfirst"></span><span id="capfirst"></span><span id="std:templatefilter-capfirst"></span><h3>capfirst<a class="headerlink" href="#capfirst" title="Permalink to this headline">¶</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"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;django&quot;</span></tt>, the output will be <tt class="docutils literal"><span class="pre">&quot;Django&quot;</span></tt>.</p>
</div>
<div class="section" id="s-center">
<span id="s-std:templatefilter-center"></span><span id="center"></span><span id="std:templatefilter-center"></span><h3>center<a class="headerlink" href="#center" title="Permalink to this headline">¶</a></h3>
<p>Centers the value in a field of a given width.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre>&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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;Django&quot;</span></tt>, the output will be <tt class="docutils literal"><span class="pre">&quot;</span>&nbsp;&nbsp;&nbsp;&nbsp; <span class="pre">Django</span>&nbsp;&nbsp;&nbsp; <span class="pre">&quot;</span></tt>.</p>
</div>
<div class="section" id="s-cut">
<span id="s-std:templatefilter-cut"></span><span id="cut"></span><span id="std:templatefilter-cut"></span><h3>cut<a class="headerlink" href="#cut" title="Permalink to this headline">¶</a></h3>
<p>Removes all values of arg from the given string.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;String</span> <span class="pre">with</span> <span class="pre">spaces&quot;</span></tt>, the output will be
<tt class="docutils literal"><span class="pre">&quot;Stringwithspaces&quot;</span></tt>.</p>
</div>
<div class="section" id="s-date">
<span id="s-std:templatefilter-date"></span><span id="date"></span><span id="std:templatefilter-date"></span><h3>date<a class="headerlink" href="#date" title="Permalink to this headline">¶</a></h3>
<p>Formats a date according to the given format.</p>
<p>Uses a similar format as PHP&#8217;s <tt class="docutils literal"><span class="pre">date()</span></tt> function (<a class="reference external" href="http://php.net/date">http://php.net/date</a>)
with some differences.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">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>Available format strings:</p>
<table class="docutils">
<colgroup>
<col width="12%" />
<col width="31%" />
<col width="57%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Format character</th>
<th class="head">Description</th>
<th class="head">Example output</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>a</td>
<td><tt class="docutils literal"><span class="pre">'a.m.'</span></tt> or <tt class="docutils literal"><span class="pre">'p.m.'</span></tt> (Note that
this is slightly different than PHP&#8217;s
output, because this includes periods
to match Associated Press style.)</td>
<td><tt class="docutils literal"><span class="pre">'a.m.'</span></tt></td>
</tr>
<tr class="row-odd"><td>A</td>
<td><tt class="docutils literal"><span class="pre">'AM'</span></tt> or <tt class="docutils literal"><span class="pre">'PM'</span></tt>.</td>
<td><tt class="docutils literal"><span class="pre">'AM'</span></tt></td>
</tr>
<tr class="row-even"><td>b</td>
<td>Month, textual, 3 letters, lowercase.</td>
<td><tt class="docutils literal"><span class="pre">'jan'</span></tt></td>
</tr>
<tr class="row-odd"><td>B</td>
<td>Not implemented.</td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td>c</td>
<td>ISO 8601 format. (Note: unlike others
formatters, such as &#8220;Z&#8221;, &#8220;O&#8221; or &#8220;r&#8221;,
the &#8220;c&#8221; formatter will not add timezone
offset if value is a naive datetime
(see <tt class="xref py py-class docutils literal"><span class="pre">datetime.tzinfo</span></tt>).</td>
<td><tt class="docutils literal"><span class="pre">2008-01-02T10:30:00.000123+02:00</span></tt>,
or <tt class="docutils literal"><span class="pre">2008-01-02T10:30:00.000123</span></tt> if the datetime is naive</td>
</tr>
<tr class="row-odd"><td>d</td>
<td>Day of the month, 2 digits with
leading zeros.</td>
<td><tt class="docutils literal"><span class="pre">'01'</span></tt> to <tt class="docutils literal"><span class="pre">'31'</span></tt></td>
</tr>
<tr class="row-even"><td>D</td>
<td>Day of the week, textual, 3 letters.</td>
<td><tt class="docutils literal"><span class="pre">'Fri'</span></tt></td>
</tr>
<tr class="row-odd"><td>e</td>
<td>Timezone name. Could be in any format,
or might return an empty string,
depending on the datetime.</td>
<td><tt class="docutils literal"><span class="pre">''</span></tt>, <tt class="docutils literal"><span class="pre">'GMT'</span></tt>, <tt class="docutils literal"><span class="pre">'-500'</span></tt>, <tt class="docutils literal"><span class="pre">'US/Eastern'</span></tt>, etc.</td>
</tr>
<tr class="row-even"><td>E</td>
<td>Month, locale specific alternative
representation usually used for long
date representation.</td>
<td><tt class="docutils literal"><span class="pre">'listopada'</span></tt> (for Polish locale, as opposed to <tt class="docutils literal"><span class="pre">'Listopad'</span></tt>)</td>
</tr>
<tr class="row-odd"><td>f</td>
<td>Time, in 12-hour hours and minutes,
with minutes left off if they&#8217;re zero.
Proprietary extension.</td>
<td><tt class="docutils literal"><span class="pre">'1'</span></tt>, <tt class="docutils literal"><span class="pre">'1:30'</span></tt></td>
</tr>
<tr class="row-even"><td>F</td>
<td>Month, textual, long.</td>
<td><tt class="docutils literal"><span class="pre">'January'</span></tt></td>
</tr>
<tr class="row-odd"><td>g</td>
<td>Hour, 12-hour format without leading
zeros.</td>
<td><tt class="docutils literal"><span class="pre">'1'</span></tt> to <tt class="docutils literal"><span class="pre">'12'</span></tt></td>
</tr>
<tr class="row-even"><td>G</td>
<td>Hour, 24-hour format without leading
zeros.</td>
<td><tt class="docutils literal"><span class="pre">'0'</span></tt> to <tt class="docutils literal"><span class="pre">'23'</span></tt></td>
</tr>
<tr class="row-odd"><td>h</td>
<td>Hour, 12-hour format.</td>
<td><tt class="docutils literal"><span class="pre">'01'</span></tt> to <tt class="docutils literal"><span class="pre">'12'</span></tt></td>
</tr>
<tr class="row-even"><td>H</td>
<td>Hour, 24-hour format.</td>
<td><tt class="docutils literal"><span class="pre">'00'</span></tt> to <tt class="docutils literal"><span class="pre">'23'</span></tt></td>
</tr>
<tr class="row-odd"><td>i</td>
<td>Minutes.</td>
<td><tt class="docutils literal"><span class="pre">'00'</span></tt> to <tt class="docutils literal"><span class="pre">'59'</span></tt></td>
</tr>
<tr class="row-even"><td>I</td>
<td>Daylight Savings Time, whether it&#8217;s
in effect or not.</td>
<td><tt class="docutils literal"><span class="pre">'1'</span></tt> or <tt class="docutils literal"><span class="pre">'0'</span></tt></td>
</tr>
<tr class="row-odd"><td>j</td>
<td>Day of the month without leading
zeros.</td>
<td><tt class="docutils literal"><span class="pre">'1'</span></tt> to <tt class="docutils literal"><span class="pre">'31'</span></tt></td>
</tr>
<tr class="row-even"><td>l</td>
<td>Day of the week, textual, long.</td>
<td><tt class="docutils literal"><span class="pre">'Friday'</span></tt></td>
</tr>
<tr class="row-odd"><td>L</td>
<td>Boolean for whether it&#8217;s a leap year.</td>
<td><tt class="docutils literal"><span class="pre">True</span></tt> or <tt class="docutils literal"><span class="pre">False</span></tt></td>
</tr>
<tr class="row-even"><td>m</td>
<td>Month, 2 digits with leading zeros.</td>
<td><tt class="docutils literal"><span class="pre">'01'</span></tt> to <tt class="docutils literal"><span class="pre">'12'</span></tt></td>
</tr>
<tr class="row-odd"><td>M</td>
<td>Month, textual, 3 letters.</td>
<td><tt class="docutils literal"><span class="pre">'Jan'</span></tt></td>
</tr>
<tr class="row-even"><td>n</td>
<td>Month without leading zeros.</td>
<td><tt class="docutils literal"><span class="pre">'1'</span></tt> to <tt class="docutils literal"><span class="pre">'12'</span></tt></td>
</tr>
<tr class="row-odd"><td>N</td>
<td>Month abbreviation in Associated Press
style. Proprietary extension.</td>
<td><tt class="docutils literal"><span class="pre">'Jan.'</span></tt>, <tt class="docutils literal"><span class="pre">'Feb.'</span></tt>, <tt class="docutils literal"><span class="pre">'March'</span></tt>, <tt class="docutils literal"><span class="pre">'May'</span></tt></td>
</tr>
<tr class="row-even"><td>o</td>
<td>ISO-8601 week-numbering year,
corresponding to
the ISO-8601 week number (W)</td>
<td><tt class="docutils literal"><span class="pre">'1999'</span></tt></td>
</tr>
<tr class="row-odd"><td>O</td>
<td>Difference to Greenwich time in hours.</td>
<td><tt class="docutils literal"><span class="pre">'+0200'</span></tt></td>
</tr>
<tr class="row-even"><td>P</td>
<td>Time, in 12-hour hours, minutes and
&#8216;a.m.&#8217;/&#8217;p.m.&#8217;, with minutes left off
if they&#8217;re zero and the special-case
strings &#8216;midnight&#8217; and &#8216;noon&#8217; if
appropriate. Proprietary extension.</td>
<td><tt class="docutils literal"><span class="pre">'1</span> <span class="pre">a.m.'</span></tt>, <tt class="docutils literal"><span class="pre">'1:30</span> <span class="pre">p.m.'</span></tt>, <tt class="docutils literal"><span class="pre">'midnight'</span></tt>, <tt class="docutils literal"><span class="pre">'noon'</span></tt>, <tt class="docutils literal"><span class="pre">'12:30</span> <span class="pre">p.m.'</span></tt></td>
</tr>
<tr class="row-odd"><td>r</td>
<td><span class="target" id="index-0"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc2822.html"><strong>RFC 2822</strong></a> formatted date.</td>
<td><tt class="docutils literal"><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></tt></td>
</tr>
<tr class="row-even"><td>s</td>
<td>Seconds, 2 digits with leading zeros.</td>
<td><tt class="docutils literal"><span class="pre">'00'</span></tt> to <tt class="docutils literal"><span class="pre">'59'</span></tt></td>
</tr>
<tr class="row-odd"><td>S</td>
<td>English ordinal suffix for day of the
month, 2 characters.</td>
<td><tt class="docutils literal"><span class="pre">'st'</span></tt>, <tt class="docutils literal"><span class="pre">'nd'</span></tt>, <tt class="docutils literal"><span class="pre">'rd'</span></tt> or <tt class="docutils literal"><span class="pre">'th'</span></tt></td>
</tr>
<tr class="row-even"><td>t</td>
<td>Number of days in the given month.</td>
<td><tt class="docutils literal"><span class="pre">28</span></tt> to <tt class="docutils literal"><span class="pre">31</span></tt></td>
</tr>
<tr class="row-odd"><td>T</td>
<td>Time zone of this machine.</td>
<td><tt class="docutils literal"><span class="pre">'EST'</span></tt>, <tt class="docutils literal"><span class="pre">'MDT'</span></tt></td>
</tr>
<tr class="row-even"><td>u</td>
<td>Microseconds.</td>
<td><tt class="docutils literal"><span class="pre">000000</span></tt> to <tt class="docutils literal"><span class="pre">999999</span></tt></td>
</tr>
<tr class="row-odd"><td>U</td>
<td>Seconds since the Unix Epoch
(January 1 1970 00:00:00 UTC).</td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td>w</td>
<td>Day of the week, digits without
leading zeros.</td>
<td><tt class="docutils literal"><span class="pre">'0'</span></tt> (Sunday) to <tt class="docutils literal"><span class="pre">'6'</span></tt> (Saturday)</td>
</tr>
<tr class="row-odd"><td>W</td>
<td>ISO-8601 week number of year, with
weeks starting on Monday.</td>
<td><tt class="docutils literal"><span class="pre">1</span></tt>, <tt class="docutils literal"><span class="pre">53</span></tt></td>
</tr>
<tr class="row-even"><td>y</td>
<td>Year, 2 digits.</td>
<td><tt class="docutils literal"><span class="pre">'99'</span></tt></td>
</tr>
<tr class="row-odd"><td>Y</td>
<td>Year, 4 digits.</td>
<td><tt class="docutils literal"><span class="pre">'1999'</span></tt></td>
</tr>
<tr class="row-even"><td>z</td>
<td>Day of the year.</td>
<td><tt class="docutils literal"><span class="pre">0</span></tt> to <tt class="docutils literal"><span class="pre">365</span></tt></td>
</tr>
<tr class="row-odd"><td>Z</td>
<td>Time zone offset in seconds. The
offset for timezones west of UTC is
always negative, and for those east of
UTC is always positive.</td>
<td><tt class="docutils literal"><span class="pre">-43200</span></tt> to <tt class="docutils literal"><span class="pre">43200</span></tt></td>
</tr>
</tbody>
</table>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is a <tt class="docutils literal"><span class="pre">datetime</span></tt> object (e.g., the result of
<tt class="docutils literal"><span class="pre">datetime.datetime.now()</span></tt>), the output will be the string
<tt class="docutils literal"><span class="pre">'Wed</span> <span class="pre">09</span> <span class="pre">Jan</span> <span class="pre">2008'</span></tt>.</p>
<p>The format passed can be one of the predefined ones <a class="reference internal" href="../settings.html#std:setting-DATE_FORMAT"><tt class="xref std std-setting docutils literal"><span class="pre">DATE_FORMAT</span></tt></a>,
<a class="reference internal" href="../settings.html#std:setting-DATETIME_FORMAT"><tt class="xref std std-setting docutils literal"><span class="pre">DATETIME_FORMAT</span></tt></a>, <a class="reference internal" href="../settings.html#std:setting-SHORT_DATE_FORMAT"><tt class="xref std std-setting docutils literal"><span class="pre">SHORT_DATE_FORMAT</span></tt></a> or
<a class="reference internal" href="../settings.html#std:setting-SHORT_DATETIME_FORMAT"><tt class="xref std std-setting docutils literal"><span class="pre">SHORT_DATETIME_FORMAT</span></tt></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-USE_L10N"><tt class="xref std std-setting docutils literal"><span class="pre">USE_L10N</span></tt></a> is <tt class="docutils literal"><span class="pre">True</span></tt> and <a class="reference internal" href="../settings.html#std:setting-LANGUAGE_CODE"><tt class="xref std std-setting docutils literal"><span class="pre">LANGUAGE_CODE</span></tt></a> is,
for example, <tt class="docutils literal"><span class="pre">&quot;es&quot;</span></tt>, then for:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">&quot;09/01/2008&quot;</span></tt> (the <tt class="docutils literal"><span class="pre">&quot;SHORT_DATE_FORMAT&quot;</span></tt>
format specifier for the <tt class="docutils literal"><span class="pre">es</span></tt> locale as shipped with Django is <tt class="docutils literal"><span class="pre">&quot;d/m/Y&quot;</span></tt>).</p>
<p>When used without a format string:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>...the formatting string defined in the <a class="reference internal" href="../settings.html#std:setting-DATE_FORMAT"><tt class="xref std std-setting docutils literal"><span class="pre">DATE_FORMAT</span></tt></a> setting will be
used, without applying any localization.</p>
</div>
<div class="section" id="s-default">
<span id="s-std:templatefilter-default"></span><span id="default"></span><span id="std:templatefilter-default"></span><h3>default<a class="headerlink" href="#default" title="Permalink to this headline">¶</a></h3>
<p>If value evaluates to <tt class="docutils literal"><span class="pre">False</span></tt>, uses the given default. Otherwise, uses the
value.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;&quot;</span></tt> (the empty string), the output will be <tt class="docutils literal"><span class="pre">nothing</span></tt>.</p>
</div>
<div class="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>default_if_none<a class="headerlink" href="#default-if-none" title="Permalink to this headline">¶</a></h3>
<p>If (and only if) value is <tt class="docutils literal"><span class="pre">None</span></tt>, 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"><tt class="xref std std-tfilter docutils literal"><span class="pre">default</span></tt></a> filter if you want to fallback for empty strings.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">None</span></tt>, the output will be the string <tt class="docutils literal"><span class="pre">&quot;nothing&quot;</span></tt>.</p>
</div>
<div class="section" id="s-dictsort">
<span id="s-std:templatefilter-dictsort"></span><span id="dictsort"></span><span id="std:templatefilter-dictsort"></span><h3>dictsort<a class="headerlink" href="#dictsort" title="Permalink to this headline">¶</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"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">[</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;zed&#39;</span><span class="p">,</span> <span class="s">&#39;age&#39;</span><span class="p">:</span> <span class="mi">19</span><span class="p">},</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;amy&#39;</span><span class="p">,</span> <span class="s">&#39;age&#39;</span><span class="p">:</span> <span class="mi">22</span><span class="p">},</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;joe&#39;</span><span class="p">,</span> <span class="s">&#39;age&#39;</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"><div class="highlight"><pre><span class="p">[</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;amy&#39;</span><span class="p">,</span> <span class="s">&#39;age&#39;</span><span class="p">:</span> <span class="mi">22</span><span class="p">},</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;joe&#39;</span><span class="p">,</span> <span class="s">&#39;age&#39;</span><span class="p">:</span> <span class="mi">31</span><span class="p">},</span>
    <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;zed&#39;</span><span class="p">,</span> <span class="s">&#39;age&#39;</span><span class="p">:</span> <span class="mi">19</span><span class="p">},</span>
<span class="p">]</span>
</pre></div>
</div>
</div>
<div class="section" id="s-dictsortreversed">
<span id="s-std:templatefilter-dictsortreversed"></span><span id="dictsortreversed"></span><span id="std:templatefilter-dictsortreversed"></span><h3>dictsortreversed<a class="headerlink" href="#dictsortreversed" title="Permalink to this headline">¶</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>
</div>
<div class="section" id="s-divisibleby">
<span id="s-std:templatefilter-divisibleby"></span><span id="divisibleby"></span><span id="std:templatefilter-divisibleby"></span><h3>divisibleby<a class="headerlink" href="#divisibleby" title="Permalink to this headline">¶</a></h3>
<p>Returns <tt class="docutils literal"><span class="pre">True</span></tt> if the value is divisible by the argument.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">21</span></tt>, the output would be <tt class="docutils literal"><span class="pre">True</span></tt>.</p>
</div>
<div class="section" id="s-escape">
<span id="s-std:templatefilter-escape"></span><span id="escape"></span><span id="std:templatefilter-escape"></span><h3>escape<a class="headerlink" href="#escape" title="Permalink to this headline">¶</a></h3>
<p>Escapes a string&#8217;s HTML. Specifically, it makes these replacements:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">&lt;</span></tt> is converted to <tt class="docutils literal"><span class="pre">&amp;lt;</span></tt></li>
<li><tt class="docutils literal"><span class="pre">&gt;</span></tt> is converted to <tt class="docutils literal"><span class="pre">&amp;gt;</span></tt></li>
<li><tt class="docutils literal"><span class="pre">'</span></tt> (single quote) is converted to <tt class="docutils literal"><span class="pre">&amp;#39;</span></tt></li>
<li><tt class="docutils literal"><span class="pre">&quot;</span></tt> (double quote) is converted to <tt class="docutils literal"><span class="pre">&amp;quot;</span></tt></li>
<li><tt class="docutils literal"><span class="pre">&amp;</span></tt> is converted to <tt class="docutils literal"><span class="pre">&amp;amp;</span></tt></li>
</ul>
<p>The escaping is only applied when the string is output, so it does not matter
where in a chained sequence of filters you put <tt class="docutils literal"><span class="pre">escape</span></tt>: it will always be
applied as though it were the last filter. If you want escaping to be applied
immediately, use the <a class="reference internal" href="#std:templatefilter-force_escape"><tt class="xref std std-tfilter docutils literal"><span class="pre">force_escape</span></tt></a> filter.</p>
<p>Applying <tt class="docutils literal"><span class="pre">escape</span></tt> 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"><tt class="xref std std-tfilter docutils literal"><span class="pre">force_escape</span></tt></a> filter.</p>
<p>For example, you can apply <tt class="docutils literal"><span class="pre">escape</span></tt> to fields when <a class="reference internal" href="#std:templatetag-autoescape"><tt class="xref std std-ttag docutils literal"><span class="pre">autoescape</span></tt></a> is off:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>
<div class="section" id="s-escapejs">
<span id="s-std:templatefilter-escapejs"></span><span id="escapejs"></span><span id="std:templatefilter-escapejs"></span><h3>escapejs<a class="headerlink" href="#escapejs" title="Permalink to this headline">¶</a></h3>
<p>Escapes characters for use in JavaScript strings. This does <em>not</em> make the
string safe for use in HTML, but does protect you from syntax errors when using
templates to generate JavaScript/JSON.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">escapejs</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;testing\r\njavascript</span> <span class="pre">\'string&quot;</span> <span class="pre">&lt;b&gt;escaping&lt;/b&gt;&quot;</span></tt>,
the output will be <tt class="docutils literal"><span class="pre">&quot;testing\\u000D\\u000Ajavascript</span> <span class="pre">\\u0027string\\u0022</span> <span class="pre">\\u003Cb\\u003Eescaping\\u003C/b\\u003E&quot;</span></tt>.</p>
</div>
<div class="section" id="s-filesizeformat">
<span id="s-std:templatefilter-filesizeformat"></span><span id="filesizeformat"></span><span id="std:templatefilter-filesizeformat"></span><h3>filesizeformat<a class="headerlink" href="#filesizeformat" title="Permalink to this headline">¶</a></h3>
<p>Formats the value like a &#8216;human-readable&#8217; file size (i.e. <tt class="docutils literal"><span class="pre">'13</span> <span class="pre">KB'</span></tt>,
<tt class="docutils literal"><span class="pre">'4.1</span> <span class="pre">MB'</span></tt>, <tt class="docutils literal"><span class="pre">'102</span> <span class="pre">bytes'</span></tt>, etc).</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is 123456789, the output would be <tt class="docutils literal"><span class="pre">117.7</span> <span class="pre">MB</span></tt>.</p>
<div class="admonition-file-sizes-and-si-units admonition">
<p class="first admonition-title">File sizes and SI units</p>
<p class="last">Strictly speaking, <tt class="docutils literal"><span class="pre">filesizeformat</span></tt> 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>
</div>
<div class="section" id="s-first">
<span id="s-std:templatefilter-first"></span><span id="first"></span><span id="std:templatefilter-first"></span><h3>first<a class="headerlink" href="#first" title="Permalink to this headline">¶</a></h3>
<p>Returns the first item in a list.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is the list <tt class="docutils literal"><span class="pre">['a',</span> <span class="pre">'b',</span> <span class="pre">'c']</span></tt>, the output will be <tt class="docutils literal"><span class="pre">'a'</span></tt>.</p>
</div>
<div class="section" id="s-fix-ampersands">
<span id="s-std:templatefilter-fix_ampersands"></span><span id="fix-ampersands"></span><span id="std:templatefilter-fix_ampersands"></span><h3>fix_ampersands<a class="headerlink" href="#fix-ampersands" title="Permalink to this headline">¶</a></h3>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This is rarely useful as ampersands are automatically escaped. See
<a class="reference internal" href="#std:templatefilter-escape"><tt class="xref std std-tfilter docutils literal"><span class="pre">escape</span></tt></a> for more information.</p>
</div>
<p>Replaces ampersands with <tt class="docutils literal"><span class="pre">&amp;amp;</span></tt> entities.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">fix_ampersands</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">Tom</span> <span class="pre">&amp;</span> <span class="pre">Jerry</span></tt>, the output will be <tt class="docutils literal"><span class="pre">Tom</span> <span class="pre">&amp;amp;</span> <span class="pre">Jerry</span></tt>.</p>
<p>However, ampersands used in named entities and numeric character references
will not be replaced. For example, if <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">Caf&amp;eacute;</span></tt>, the output
will <em>not</em> be <tt class="docutils literal"><span class="pre">Caf&amp;amp;eacute;</span></tt> but remain <tt class="docutils literal"><span class="pre">Caf&amp;eacute;</span></tt>. This means that
in some edge cases, such as acronyms followed by semicolons, this filter will
not replace ampersands that need replacing. For example, if <tt class="docutils literal"><span class="pre">value</span></tt> is
<tt class="docutils literal"><span class="pre">Contact</span> <span class="pre">the</span> <span class="pre">R&amp;D;</span></tt>, the output will remain unchanged because <tt class="docutils literal"><span class="pre">&amp;D;</span></tt>
resembles a named entity.</p>
</div>
<div class="section" id="s-floatformat">
<span id="s-std:templatefilter-floatformat"></span><span id="floatformat"></span><span id="std:templatefilter-floatformat"></span><h3>floatformat<a class="headerlink" href="#floatformat" title="Permalink to this headline">¶</a></h3>
<p>When used without an argument, rounds a floating-point number to one decimal
place &#8211; but only if there&#8217;s a decimal part to be displayed. For example:</p>
<table class="docutils">
<colgroup>
<col width="26%" />
<col width="57%" />
<col width="17%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><tt class="docutils literal"><span class="pre">value</span></tt></th>
<th class="head">Template</th>
<th class="head">Output</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">34.23234</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">value|floatformat</span> <span class="pre">}}</span></tt></td>
<td><tt class="docutils literal"><span class="pre">34.2</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">34.00000</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">value|floatformat</span> <span class="pre">}}</span></tt></td>
<td><tt class="docutils literal"><span class="pre">34</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">34.26000</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">value|floatformat</span> <span class="pre">}}</span></tt></td>
<td><tt class="docutils literal"><span class="pre">34.3</span></tt></td>
</tr>
</tbody>
</table>
<p>If used with a numeric integer argument, <tt class="docutils literal"><span class="pre">floatformat</span></tt> rounds a number to
that many decimal places. For example:</p>
<table class="docutils">
<colgroup>
<col width="24%" />
<col width="57%" />
<col width="20%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><tt class="docutils literal"><span class="pre">value</span></tt></th>
<th class="head">Template</th>
<th class="head">Output</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">34.23234</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">value|floatformat:3</span> <span class="pre">}}</span></tt></td>
<td><tt class="docutils literal"><span class="pre">34.232</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">34.00000</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">value|floatformat:3</span> <span class="pre">}}</span></tt></td>
<td><tt class="docutils literal"><span class="pre">34.000</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">34.26000</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">value|floatformat:3</span> <span class="pre">}}</span></tt></td>
<td><tt class="docutils literal"><span class="pre">34.260</span></tt></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">
<colgroup>
<col width="22%" />
<col width="59%" />
<col width="19%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><tt class="docutils literal"><span class="pre">value</span></tt></th>
<th class="head">Template</th>
<th class="head">Output</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">34.23234</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;0&quot;</span> <span class="pre">}}</span></tt></td>
<td><tt class="docutils literal"><span class="pre">34</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">34.00000</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;0&quot;</span> <span class="pre">}}</span></tt></td>
<td><tt class="docutils literal"><span class="pre">34</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">39.56000</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;0&quot;</span> <span class="pre">}}</span></tt></td>
<td><tt class="docutils literal"><span class="pre">40</span></tt></td>
</tr>
</tbody>
</table>
<p>If the argument passed to <tt class="docutils literal"><span class="pre">floatformat</span></tt> is negative, it will round a number
to that many decimal places &#8211; but only if there&#8217;s a decimal part to be
displayed. For example:</p>
<table class="docutils">
<colgroup>
<col width="22%" />
<col width="59%" />
<col width="19%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><tt class="docutils literal"><span class="pre">value</span></tt></th>
<th class="head">Template</th>
<th class="head">Output</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">34.23234</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;-3&quot;</span> <span class="pre">}}</span></tt></td>
<td><tt class="docutils literal"><span class="pre">34.232</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">34.00000</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;-3&quot;</span> <span class="pre">}}</span></tt></td>
<td><tt class="docutils literal"><span class="pre">34</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">34.26000</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">value|floatformat:&quot;-3&quot;</span> <span class="pre">}}</span></tt></td>
<td><tt class="docutils literal"><span class="pre">34.260</span></tt></td>
</tr>
</tbody>
</table>
<p>Using <tt class="docutils literal"><span class="pre">floatformat</span></tt> with no argument is equivalent to using <tt class="docutils literal"><span class="pre">floatformat</span></tt>
with an argument of <tt class="docutils literal"><span class="pre">-1</span></tt>.</p>
</div>
<div class="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>force_escape<a class="headerlink" href="#force-escape" title="Permalink to this headline">¶</a></h3>
<p>Applies HTML escaping to a string (see the <a class="reference internal" href="#std:templatefilter-escape"><tt class="xref std std-tfilter docutils literal"><span class="pre">escape</span></tt></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"><tt class="xref std std-tfilter docutils literal"><span class="pre">escape</span></tt></a> filter.</p>
<p>For example, if you want to catch the <tt class="docutils literal"><span class="pre">&lt;p&gt;</span></tt> HTML elements created by
the <a class="reference internal" href="#std:templatefilter-linebreaks"><tt class="xref std std-tfilter docutils literal"><span class="pre">linebreaks</span></tt></a> filter:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>
</div>
<div class="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>get_digit<a class="headerlink" href="#get-digit" title="Permalink to this headline">¶</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"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">123456789</span></tt>, the output will be <tt class="docutils literal"><span class="pre">8</span></tt>.</p>
</div>
<div class="section" id="s-iriencode">
<span id="s-std:templatefilter-iriencode"></span><span id="iriencode"></span><span id="std:templatefilter-iriencode"></span><h3>iriencode<a class="headerlink" href="#iriencode" title="Permalink to this headline">¶</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&#8217;re trying to use
strings containing non-ASCII characters in a URL.</p>
<p>It&#8217;s safe to use this filter on a string that has already gone through the
<a class="reference internal" href="#std:templatefilter-urlencode"><tt class="xref std std-tfilter docutils literal"><span class="pre">urlencode</span></tt></a> filter.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;?test=1&amp;me=2&quot;</span></tt>, the output will be <tt class="docutils literal"><span class="pre">&quot;?test=1&amp;amp;me=2&quot;</span></tt>.</p>
</div>
<div class="section" id="s-join">
<span id="s-std:templatefilter-join"></span><span id="join"></span><span id="std:templatefilter-join"></span><h3>join<a class="headerlink" href="#join" title="Permalink to this headline">¶</a></h3>
<p>Joins a list with a string, like Python&#8217;s <tt class="docutils literal"><span class="pre">str.join(list)</span></tt></p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is the list <tt class="docutils literal"><span class="pre">['a',</span> <span class="pre">'b',</span> <span class="pre">'c']</span></tt>, the output will be the string
<tt class="docutils literal"><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></tt>.</p>
</div>
<div class="section" id="s-last">
<span id="s-std:templatefilter-last"></span><span id="last"></span><span id="std:templatefilter-last"></span><h3>last<a class="headerlink" href="#last" title="Permalink to this headline">¶</a></h3>
<p>Returns the last item in a list.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is the list <tt class="docutils literal"><span class="pre">['a',</span> <span class="pre">'b',</span> <span class="pre">'c',</span> <span class="pre">'d']</span></tt>, the output will be the
string <tt class="docutils literal"><span class="pre">&quot;d&quot;</span></tt>.</p>
</div>
<div class="section" id="s-length">
<span id="s-std:templatefilter-length"></span><span id="length"></span><span id="std:templatefilter-length"></span><h3>length<a class="headerlink" href="#length" title="Permalink to this headline">¶</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"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">['a',</span> <span class="pre">'b',</span> <span class="pre">'c',</span> <span class="pre">'d']</span></tt>, the output will be <tt class="docutils literal"><span class="pre">4</span></tt>.</p>
</div>
<div class="section" id="s-length-is">
<span id="s-std:templatefilter-length_is"></span><span id="length-is"></span><span id="std:templatefilter-length_is"></span><h3>length_is<a class="headerlink" href="#length-is" title="Permalink to this headline">¶</a></h3>
<p>Returns <tt class="docutils literal"><span class="pre">True</span></tt> if the value&#8217;s length is the argument, or <tt class="docutils literal"><span class="pre">False</span></tt> otherwise.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">length_is</span><span class="s2">:&quot;4&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">['a',</span> <span class="pre">'b',</span> <span class="pre">'c',</span> <span class="pre">'d']</span></tt>, the output will be <tt class="docutils literal"><span class="pre">True</span></tt>.</p>
</div>
<div class="section" id="s-linebreaks">
<span id="s-std:templatefilter-linebreaks"></span><span id="linebreaks"></span><span id="std:templatefilter-linebreaks"></span><h3>linebreaks<a class="headerlink" href="#linebreaks" title="Permalink to this headline">¶</a></h3>
<p>Replaces line breaks in plain text with appropriate HTML; a single
newline becomes an HTML line break (<tt class="docutils literal"><span class="pre">&lt;br</span> <span class="pre">/&gt;</span></tt>) and a new line
followed by a blank line becomes a paragraph break (<tt class="docutils literal"><span class="pre">&lt;/p&gt;</span></tt>).</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">Joel\nis</span> <span class="pre">a</span> <span class="pre">slug</span></tt>, the output will be <tt class="docutils literal"><span class="pre">&lt;p&gt;Joel&lt;br</span> <span class="pre">/&gt;is</span> <span class="pre">a</span>
<span class="pre">slug&lt;/p&gt;</span></tt>.</p>
</div>
<div class="section" id="s-linebreaksbr">
<span id="s-std:templatefilter-linebreaksbr"></span><span id="linebreaksbr"></span><span id="std:templatefilter-linebreaksbr"></span><h3>linebreaksbr<a class="headerlink" href="#linebreaksbr" title="Permalink to this headline">¶</a></h3>
<p>Converts all newlines in a piece of plain text to HTML line breaks
(<tt class="docutils literal"><span class="pre">&lt;br</span> <span class="pre">/&gt;</span></tt>).</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">Joel\nis</span> <span class="pre">a</span> <span class="pre">slug</span></tt>, the output will be <tt class="docutils literal"><span class="pre">Joel&lt;br</span> <span class="pre">/&gt;is</span> <span class="pre">a</span>
<span class="pre">slug</span></tt>.</p>
</div>
<div class="section" id="s-linenumbers">
<span id="s-std:templatefilter-linenumbers"></span><span id="linenumbers"></span><span id="std:templatefilter-linenumbers"></span><h3>linenumbers<a class="headerlink" href="#linenumbers" title="Permalink to this headline">¶</a></h3>
<p>Displays text with line numbers.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is:</p>
<div class="highlight-html+django"><div class="highlight"><pre>one
two
three
</pre></div>
</div>
<p>the output will be:</p>
<div class="highlight-html+django"><div class="highlight"><pre>1. one
2. two
3. three
</pre></div>
</div>
</div>
<div class="section" id="s-ljust">
<span id="s-std:templatefilter-ljust"></span><span id="ljust"></span><span id="std:templatefilter-ljust"></span><h3>ljust<a class="headerlink" href="#ljust" title="Permalink to this headline">¶</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"><div class="highlight"><pre>&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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">Django</span></tt>, the output will be <tt class="docutils literal"><span class="pre">&quot;Django</span>&nbsp;&nbsp;&nbsp; <span class="pre">&quot;</span></tt>.</p>
</div>
<div class="section" id="s-lower">
<span id="s-std:templatefilter-lower"></span><span id="lower"></span><span id="std:templatefilter-lower"></span><h3>lower<a class="headerlink" href="#lower" title="Permalink to this headline">¶</a></h3>
<p>Converts a string into all lowercase.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">Still</span> <span class="pre">MAD</span> <span class="pre">At</span> <span class="pre">Yoko</span></tt>, the output will be
<tt class="docutils literal"><span class="pre">still</span> <span class="pre">mad</span> <span class="pre">at</span> <span class="pre">yoko</span></tt>.</p>
</div>
<div class="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>make_list<a class="headerlink" href="#make-list" title="Permalink to this headline">¶</a></h3>
<p>Returns the value turned into a list. For a string, it&#8217;s a list of characters.
For an integer, the argument is cast into an unicode string before creating a
list.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is the string <tt class="docutils literal"><span class="pre">&quot;Joel&quot;</span></tt>, the output would be the list
<tt class="docutils literal"><span class="pre">[u'J',</span> <span class="pre">u'o',</span> <span class="pre">u'e',</span> <span class="pre">u'l']</span></tt>. If <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">123</span></tt>, the output will be the
list <tt class="docutils literal"><span class="pre">[u'1',</span> <span class="pre">u'2',</span> <span class="pre">u'3']</span></tt>.</p>
</div>
<div class="section" id="s-phone2numeric">
<span id="s-std:templatefilter-phone2numeric"></span><span id="phone2numeric"></span><span id="std:templatefilter-phone2numeric"></span><h3>phone2numeric<a class="headerlink" href="#phone2numeric" title="Permalink to this headline">¶</a></h3>
<p>Converts a phone number (possibly containing letters) to its numerical
equivalent.</p>
<p>The input doesn&#8217;t have to be a valid phone number. This will happily convert
any string.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">800-COLLECT</span></tt>, the output will be <tt class="docutils literal"><span class="pre">800-2655328</span></tt>.</p>
</div>
<div class="section" id="s-pluralize">
<span id="s-std:templatefilter-pluralize"></span><span id="pluralize"></span><span id="std:templatefilter-pluralize"></span><h3>pluralize<a class="headerlink" href="#pluralize" title="Permalink to this headline">¶</a></h3>
<p>Returns a plural suffix if the value is not 1. By default, this suffix is
<tt class="docutils literal"><span class="pre">'s'</span></tt>.</p>
<p>Example:</p>
<div class="highlight-html+django"><div class="highlight"><pre>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 <tt class="docutils literal"><span class="pre">num_messages</span></tt> is <tt class="docutils literal"><span class="pre">1</span></tt>, the output will be <tt class="docutils literal"><span class="pre">You</span> <span class="pre">have</span> <span class="pre">1</span> <span class="pre">message.</span></tt>
If <tt class="docutils literal"><span class="pre">num_messages</span></tt> is <tt class="docutils literal"><span class="pre">2</span></tt>  the output will be <tt class="docutils literal"><span class="pre">You</span> <span class="pre">have</span> <span class="pre">2</span> <span class="pre">messages.</span></tt></p>
<p>For words that require a suffix other than <tt class="docutils literal"><span class="pre">'s'</span></tt>, you can provide an alternate
suffix as a parameter to the filter.</p>
<p>Example:</p>
<div class="highlight-html+django"><div class="highlight"><pre>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&#8217;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"><div class="highlight"><pre>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="first admonition-title">Note</p>
<p class="last">Use <a class="reference internal" href="../../topics/i18n/translation.html#std:templatetag-blocktrans"><tt class="xref std std-ttag docutils literal"><span class="pre">blocktrans</span></tt></a> to pluralize translated strings.</p>
</div>
</div>
<div class="section" id="s-pprint">
<span id="s-std:templatefilter-pprint"></span><span id="pprint"></span><span id="std:templatefilter-pprint"></span><h3>pprint<a class="headerlink" href="#pprint" title="Permalink to this headline">¶</a></h3>
<p>A wrapper around <tt class="xref py py-func docutils literal"><span class="pre">pprint.pprint()</span></tt> &#8211; for debugging, really.</p>
</div>
<div class="section" id="s-random">
<span id="s-std:templatefilter-random"></span><span id="random"></span><span id="std:templatefilter-random"></span><h3>random<a class="headerlink" href="#random" title="Permalink to this headline">¶</a></h3>
<p>Returns a random item from the given list.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is the list <tt class="docutils literal"><span class="pre">['a',</span> <span class="pre">'b',</span> <span class="pre">'c',</span> <span class="pre">'d']</span></tt>, the output could be <tt class="docutils literal"><span class="pre">&quot;b&quot;</span></tt>.</p>
</div>
<div class="section" id="s-removetags">
<span id="s-std:templatefilter-removetags"></span><span id="removetags"></span><span id="std:templatefilter-removetags"></span><h3>removetags<a class="headerlink" href="#removetags" title="Permalink to this headline">¶</a></h3>
<p>Removes a space-separated list of [X]HTML tags from the output.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{{</span> <span class="nv">value</span><span class="o">|</span><span class="nf">removetags</span><span class="s2">:&quot;b span&quot;</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><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></tt> the
unescaped output will be <tt class="docutils literal"><span class="pre">&quot;Joel</span> <span class="pre">&lt;button&gt;is&lt;/button&gt;</span> <span class="pre">a</span> <span class="pre">slug&quot;</span></tt>.</p>
<p>Note that this filter is case-sensitive.</p>
<p>If <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><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></tt> the
unescaped output will be <tt class="docutils literal"><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">slug&quot;</span></tt>.</p>
<div class="admonition-no-safety-guarantee admonition">
<p class="first admonition-title">No safety guarantee</p>
<p class="last">Note that <tt class="docutils literal"><span class="pre">removetags</span></tt> doesn&#8217;t give any guarantee about its output being
HTML safe. In particular, it doesn&#8217;t work recursively, so an input like
<tt class="docutils literal"><span class="pre">&quot;&lt;sc&lt;script&gt;ript&gt;alert('XSS')&lt;/sc&lt;/script&gt;ript&gt;&quot;</span></tt> won&#8217;t be safe even if
you apply <tt class="docutils literal"><span class="pre">|removetags:&quot;script&quot;</span></tt>. So if the input is user provided,
<strong>NEVER</strong> apply the <tt class="docutils literal"><span class="pre">safe</span></tt> filter to a <tt class="docutils literal"><span class="pre">removetags</span></tt> output. If you are
looking for something more robust, you can use the <tt class="docutils literal"><span class="pre">bleach</span></tt> Python
library, notably its <a class="reference external" href="http://bleach.readthedocs.org/en/latest/clean.html">clean</a> method.</p>
</div>
</div>
<div class="section" id="s-rjust">
<span id="s-std:templatefilter-rjust"></span><span id="rjust"></span><span id="std:templatefilter-rjust"></span><h3>rjust<a class="headerlink" href="#rjust" title="Permalink to this headline">¶</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"><div class="highlight"><pre>&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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">Django</span></tt>, the output will be <tt class="docutils literal"><span class="pre">&quot;</span>&nbsp;&nbsp;&nbsp; <span class="pre">Django&quot;</span></tt>.</p>
</div>
<div class="section" id="s-safe">
<span id="s-std:templatefilter-safe"></span><span id="safe"></span><span id="std:templatefilter-safe"></span><h3>safe<a class="headerlink" href="#safe" title="Permalink to this headline">¶</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="first admonition-title">Note</p>
<p>If you are chaining filters, a filter applied after <tt class="docutils literal"><span class="pre">safe</span></tt> can
make the contents unsafe again. For example, the following code
prints the variable as is, unescaped:</p>
<div class="last highlight-html+django"><div class="highlight"><pre><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>
</div>
<div class="section" id="s-safeseq">
<span id="s-std:templatefilter-safeseq"></span><span id="safeseq"></span><span id="std:templatefilter-safeseq"></span><h3>safeseq<a class="headerlink" href="#safeseq" title="Permalink to this headline">¶</a></h3>
<p>Applies the <a class="reference internal" href="#std:templatefilter-safe"><tt class="xref std std-tfilter docutils literal"><span class="pre">safe</span></tt></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"><tt class="xref std std-tfilter docutils literal"><span class="pre">join</span></tt></a>. For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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&#8217;t use the <a class="reference internal" href="#std:templatefilter-safe"><tt class="xref std std-tfilter docutils literal"><span class="pre">safe</span></tt></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>
</div>
<div class="section" id="s-slice">
<span id="s-std:templatefilter-slice"></span><span id="slice"></span><span id="std:templatefilter-slice"></span><h3>slice<a class="headerlink" href="#slice" title="Permalink to this headline">¶</a></h3>
<p>Returns a slice of the list.</p>
<p>Uses the same syntax as Python&#8217;s list slicing. See
<a class="reference external" href="http://www.diveintopython3.net/native-datatypes.html#slicinglists">http://www.diveintopython3.net/native-datatypes.html#slicinglists</a>
for an introduction.</p>
<p>Example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">some_list</span></tt> is <tt class="docutils literal"><span class="pre">['a',</span> <span class="pre">'b',</span> <span class="pre">'c']</span></tt>, the output will be <tt class="docutils literal"><span class="pre">['a',</span> <span class="pre">'b']</span></tt>.</p>
</div>
<div class="section" id="s-slugify">
<span id="s-std:templatefilter-slugify"></span><span id="slugify"></span><span id="std:templatefilter-slugify"></span><h3>slugify<a class="headerlink" href="#slugify" title="Permalink to this headline">¶</a></h3>
<p>Converts to lowercase, removes non-word characters (alphanumerics and
underscores) and converts spaces to hyphens. Also strips leading and trailing
whitespace.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug&quot;</span></tt>, the output will be <tt class="docutils literal"><span class="pre">&quot;joel-is-a-slug&quot;</span></tt>.</p>
</div>
<div class="section" id="s-stringformat">
<span id="s-std:templatefilter-stringformat"></span><span id="stringformat"></span><span id="std:templatefilter-stringformat"></span><h3>stringformat<a class="headerlink" href="#stringformat" title="Permalink to this headline">¶</a></h3>
<p>Formats the variable according to the argument, a string formatting specifier.
This specifier uses Python string formatting syntax, with the exception that
the leading &#8220;%&#8221; is dropped.</p>
<p>See <a class="reference external" href="http://docs.python.org/library/stdtypes.html#string-formatting-operations">http://docs.python.org/library/stdtypes.html#string-formatting-operations</a>
for documentation of Python string formatting</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">10</span></tt>, the output will be <tt class="docutils literal"><span class="pre">1.000000E+01</span></tt>.</p>
</div>
<div class="section" id="s-striptags">
<span id="s-std:templatefilter-striptags"></span><span id="striptags"></span><span id="std:templatefilter-striptags"></span><h3>striptags<a class="headerlink" href="#striptags" title="Permalink to this headline">¶</a></h3>
<p>Makes all possible efforts to strip all [X]HTML tags.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><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></tt>, the
output will be <tt class="docutils literal"><span class="pre">&quot;Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug&quot;</span></tt>.</p>
<div class="admonition-no-safety-guarantee admonition">
<p class="first admonition-title">No safety guarantee</p>
<p class="last">Note that <tt class="docutils literal"><span class="pre">striptags</span></tt> doesn&#8217;t give any guarantee about its output being
HTML safe, particularly with non valid HTML input. So <strong>NEVER</strong> apply the
<tt class="docutils literal"><span class="pre">safe</span></tt> filter to a <tt class="docutils literal"><span class="pre">striptags</span></tt> output. If you are looking for something
more robust, you can use the <tt class="docutils literal"><span class="pre">bleach</span></tt> Python library, notably its
<a class="reference external" href="http://bleach.readthedocs.org/en/latest/clean.html">clean</a> method.</p>
</div>
</div>
<div class="section" id="s-time">
<span id="s-std:templatefilter-time"></span><span id="time"></span><span id="std:templatefilter-time"></span><h3>time<a class="headerlink" href="#time" title="Permalink to this headline">¶</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"><tt class="xref std std-setting docutils literal"><span class="pre">TIME_FORMAT</span></tt></a>, or a custom
format, same as the <a class="reference internal" href="#std:templatefilter-date"><tt class="xref std std-tfilter docutils literal"><span class="pre">date</span></tt></a> filter. Note that the predefined format
is locale-dependent.</p>
<p>The time filter will only accept parameters in the format string that relate
to the time of day, not the date (for obvious reasons). If you need to
format a date, use the <a class="reference internal" href="#std:templatefilter-date"><tt class="xref std std-tfilter docutils literal"><span class="pre">date</span></tt></a> filter.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is equivalent to <tt class="docutils literal"><span class="pre">datetime.datetime.now()</span></tt>, the output will be
the string <tt class="docutils literal"><span class="pre">&quot;01:23&quot;</span></tt>.</p>
<p>Another example:</p>
<p>Assuming that <a class="reference internal" href="../settings.html#std:setting-USE_L10N"><tt class="xref std std-setting docutils literal"><span class="pre">USE_L10N</span></tt></a> is <tt class="docutils literal"><span class="pre">True</span></tt> and <a class="reference internal" href="../settings.html#std:setting-LANGUAGE_CODE"><tt class="xref std std-setting docutils literal"><span class="pre">LANGUAGE_CODE</span></tt></a> is,
for example, <tt class="docutils literal"><span class="pre">&quot;de&quot;</span></tt>, then for:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">&quot;01:23:00&quot;</span></tt> (The <tt class="docutils literal"><span class="pre">&quot;TIME_FORMAT&quot;</span></tt> format
specifier for the <tt class="docutils literal"><span class="pre">de</span></tt> locale as shipped with Django is <tt class="docutils literal"><span class="pre">&quot;H:i:s&quot;</span></tt>).</p>
<p>When used without a format string:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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>...the formatting string defined in the <a class="reference internal" href="../settings.html#std:setting-TIME_FORMAT"><tt class="xref std std-setting docutils literal"><span class="pre">TIME_FORMAT</span></tt></a> setting will be
used, without applying any localization.</p>
</div>
<div class="section" id="s-timesince">
<span id="s-std:templatefilter-timesince"></span><span id="timesince"></span><span id="std:templatefilter-timesince"></span><h3>timesince<a class="headerlink" href="#timesince" title="Permalink to this headline">¶</a></h3>
<p>Formats a date as the time since that date (e.g., &#8220;4 days, 6 hours&#8221;).</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 <tt class="docutils literal"><span class="pre">blog_date</span></tt> is a date instance representing midnight on 1
June 2006, and <tt class="docutils literal"><span class="pre">comment_date</span></tt> is a date instance for 08:00 on 1 June 2006,
then the following would return &#8220;8 hours&#8221;:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 &#8220;0 minutes&#8221; will be returned for any
date that is in the future relative to the comparison point.</p>
</div>
<div class="section" id="s-timeuntil">
<span id="s-std:templatefilter-timeuntil"></span><span id="timeuntil"></span><span id="std:templatefilter-timeuntil"></span><h3>timeuntil<a class="headerlink" href="#timeuntil" title="Permalink to this headline">¶</a></h3>
<p>Similar to <tt class="docutils literal"><span class="pre">timesince</span></tt>, except that it measures the time from now until the
given date or datetime. For example, if today is 1 June 2006 and
<tt class="docutils literal"><span class="pre">conference_date</span></tt> is a date instance holding 29 June 2006, then
<tt class="docutils literal"><span class="pre">{{</span> <span class="pre">conference_date|timeuntil</span> <span class="pre">}}</span></tt> will return &#8220;4 weeks&#8221;.</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 <tt class="docutils literal"><span class="pre">from_date</span></tt> contains 22 June
2006, then the following will return &#8220;1 week&#8221;:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 &#8220;0 minutes&#8221; will be returned for any
date that is in the past relative to the comparison point.</p>
</div>
<div class="section" id="s-title">
<span id="s-std:templatefilter-title"></span><span id="title"></span><span id="std:templatefilter-title"></span><h3>title<a class="headerlink" href="#title" title="Permalink to this headline">¶</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 &#8220;trivial words&#8221; in lowercase.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;my</span> <span class="pre">FIRST</span> <span class="pre">post&quot;</span></tt>, the output will be <tt class="docutils literal"><span class="pre">&quot;My</span> <span class="pre">First</span> <span class="pre">Post&quot;</span></tt>.</p>
</div>
<div class="section" id="s-truncatechars">
<span id="s-std:templatefilter-truncatechars"></span><span id="truncatechars"></span><span id="std:templatefilter-truncatechars"></span><h3>truncatechars<a class="headerlink" href="#truncatechars" title="Permalink to this headline">¶</a></h3>
<p>Truncates a string if it is longer than the specified number of characters.
Truncated strings will end with a translatable ellipsis sequence (&#8221;...&#8221;).</p>
<p><strong>Argument:</strong> Number of characters to truncate to</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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">9</span> <span class="cp">}}</span>
</pre></div>
</div>
<p>If <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug&quot;</span></tt>, the output will be <tt class="docutils literal"><span class="pre">&quot;Joel</span> <span class="pre">i...&quot;</span></tt>.</p>
</div>
<div class="section" id="s-truncatewords">
<span id="s-std:templatefilter-truncatewords"></span><span id="truncatewords"></span><span id="std:templatefilter-truncatewords"></span><h3>truncatewords<a class="headerlink" href="#truncatewords" title="Permalink to this headline">¶</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"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug&quot;</span></tt>, the output will be <tt class="docutils literal"><span class="pre">&quot;Joel</span> <span class="pre">is</span> <span class="pre">...&quot;</span></tt>.</p>
<p>Newlines within the string will be removed.</p>
</div>
<div class="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>truncatewords_html<a class="headerlink" href="#truncatewords-html" title="Permalink to this headline">¶</a></h3>
<p>Similar to <a class="reference internal" href="#std:templatefilter-truncatewords"><tt class="xref std std-tfilter docutils literal"><span class="pre">truncatewords</span></tt></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"><tt class="xref std std-tfilter docutils literal"><span class="pre">truncatewords</span></tt></a>, so should only be used
when it is being passed HTML text.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><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></tt>, the output will be
<tt class="docutils literal"><span class="pre">&quot;&lt;p&gt;Joel</span> <span class="pre">is</span> <span class="pre">...&lt;/p&gt;&quot;</span></tt>.</p>
<p>Newlines in the HTML content will be preserved.</p>
</div>
<div class="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>unordered_list<a class="headerlink" href="#unordered-list" title="Permalink to this headline">¶</a></h3>
<p>Recursively takes a self-nested list and returns an HTML unordered list &#8211;
WITHOUT opening and closing &lt;ul&gt; tags.</p>
<p>The list is assumed to be in the proper format. For example, if <tt class="docutils literal"><span class="pre">var</span></tt>
contains <tt class="docutils literal"><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></tt>, then
<tt class="docutils literal"><span class="pre">{{</span> <span class="pre">var|unordered_list</span> <span class="pre">}}</span></tt> would return:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="nt">&lt;li&gt;</span>States
<span class="nt">&lt;ul&gt;</span>
        <span class="nt">&lt;li&gt;</span>Kansas
        <span class="nt">&lt;ul&gt;</span>
                <span class="nt">&lt;li&gt;</span>Lawrence<span class="nt">&lt;/li&gt;</span>
                <span class="nt">&lt;li&gt;</span>Topeka<span class="nt">&lt;/li&gt;</span>
        <span class="nt">&lt;/ul&gt;</span>
        <span class="nt">&lt;/li&gt;</span>
        <span class="nt">&lt;li&gt;</span>Illinois<span class="nt">&lt;/li&gt;</span>
<span class="nt">&lt;/ul&gt;</span>
<span class="nt">&lt;/li&gt;</span>
</pre></div>
</div>
<p>Note: An older, more restrictive and verbose input format is also supported:
<tt class="docutils literal"><span class="pre">['States',</span> <span class="pre">[['Kansas',</span> <span class="pre">[['Lawrence',</span> <span class="pre">[]],</span> <span class="pre">['Topeka',</span> <span class="pre">[]]]],</span> <span class="pre">['Illinois',</span> <span class="pre">[]]]]</span></tt>,</p>
</div>
<div class="section" id="s-upper">
<span id="s-std:templatefilter-upper"></span><span id="upper"></span><span id="std:templatefilter-upper"></span><h3>upper<a class="headerlink" href="#upper" title="Permalink to this headline">¶</a></h3>
<p>Converts a string into all uppercase.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug&quot;</span></tt>, the output will be <tt class="docutils literal"><span class="pre">&quot;JOEL</span> <span class="pre">IS</span> <span class="pre">A</span> <span class="pre">SLUG&quot;</span></tt>.</p>
</div>
<div class="section" id="s-urlencode">
<span id="s-std:templatefilter-urlencode"></span><span id="urlencode"></span><span id="std:templatefilter-urlencode"></span><h3>urlencode<a class="headerlink" href="#urlencode" title="Permalink to this headline">¶</a></h3>
<p>Escapes a value for use in a URL.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;http://www.example.org/foo?a=b&amp;c=d&quot;</span></tt>, the output will be
<tt class="docutils literal"><span class="pre">&quot;http%3A//www.example.org/foo%3Fa%3Db%26c%3Dd&quot;</span></tt>.</p>
<p>An optional argument containing the characters which should not be escaped can
be provided.</p>
<p>If not provided, the &#8216;/&#8217; 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"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;http://www.example.org/&quot;</span></tt>, the output will be
<tt class="docutils literal"><span class="pre">&quot;http%3A%2F%2Fwww.example.org%2F&quot;</span></tt>.</p>
</div>
<div class="section" id="s-urlize">
<span id="s-std:templatefilter-urlize"></span><span id="urlize"></span><span id="std:templatefilter-urlize"></span><h3>urlize<a class="headerlink" href="#urlize" title="Permalink to this headline">¶</a></h3>
<p>Converts URLs and email addresses in text into clickable links.</p>
<p>This template tag works on links prefixed with <tt class="docutils literal"><span class="pre">http://</span></tt>, <tt class="docutils literal"><span class="pre">https://</span></tt>, or
<tt class="docutils literal"><span class="pre">www.</span></tt>. For example, <tt class="docutils literal"><span class="pre">http://goo.gl/aia1t</span></tt> will get converted but
<tt class="docutils literal"><span class="pre">goo.gl/aia1t</span></tt> won&#8217;t.</p>
<p>It also supports domain-only links ending in one of the original top level
domains (<tt class="docutils literal"><span class="pre">.com</span></tt>, <tt class="docutils literal"><span class="pre">.edu</span></tt>, <tt class="docutils literal"><span class="pre">.gov</span></tt>, <tt class="docutils literal"><span class="pre">.int</span></tt>, <tt class="docutils literal"><span class="pre">.mil</span></tt>, <tt class="docutils literal"><span class="pre">.net</span></tt>, and
<tt class="docutils literal"><span class="pre">.org</span></tt>). For example, <tt class="docutils literal"><span class="pre">djangoproject.com</span></tt> gets converted.</p>
<p>Links can have trailing punctuation (periods, commas, close-parens) and leading
punctuation (opening parens), and <tt class="docutils literal"><span class="pre">urlize</span></tt> will still do the right thing.</p>
<p>Links generated by <tt class="docutils literal"><span class="pre">urlize</span></tt> have a <tt class="docutils literal"><span class="pre">rel=&quot;nofollow&quot;</span></tt> attribute added
to them.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;Check</span> <span class="pre">out</span> <span class="pre">www.djangoproject.com&quot;</span></tt>, the output will be
<tt class="docutils literal"><span class="pre">&quot;Check</span> <span class="pre">out</span> <span class="pre">&lt;a</span> <span class="pre">href=&quot;http://www.djangoproject.com&quot;</span>
<span class="pre">rel=&quot;nofollow&quot;&gt;www.djangoproject.com&lt;/a&gt;&quot;</span></tt>.</p>
<p>In addition to web links, <tt class="docutils literal"><span class="pre">urlize</span></tt> also converts email addresses into
<tt class="docutils literal"><span class="pre">mailto:</span></tt> links. If <tt class="docutils literal"><span class="pre">value</span></tt> is
<tt class="docutils literal"><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></tt>, the output will be
<tt class="docutils literal"><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&lt;/a&gt;&quot;</span></tt>.</p>
<p>The <tt class="docutils literal"><span class="pre">urlize</span></tt> filter also takes an optional parameter <tt class="docutils literal"><span class="pre">autoescape</span></tt>. If
<tt class="docutils literal"><span class="pre">autoescape</span></tt> is <tt class="docutils literal"><span class="pre">True</span></tt>, the link text and URLs will be escaped using
Django&#8217;s built-in <a class="reference internal" href="#std:templatefilter-escape"><tt class="xref std std-tfilter docutils literal"><span class="pre">escape</span></tt></a> filter. The default value for
<tt class="docutils literal"><span class="pre">autoescape</span></tt> is <tt class="docutils literal"><span class="pre">True</span></tt>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If <tt class="docutils literal"><span class="pre">urlize</span></tt> is applied to text that already contains HTML markup,
things won&#8217;t work as expected. Apply this filter only to plain text.</p>
</div>
</div>
<div class="section" id="s-urlizetrunc">
<span id="s-std:templatefilter-urlizetrunc"></span><span id="urlizetrunc"></span><span id="std:templatefilter-urlizetrunc"></span><h3>urlizetrunc<a class="headerlink" href="#urlizetrunc" title="Permalink to this headline">¶</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&#8217;s added if truncation is necessary.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;Check</span> <span class="pre">out</span> <span class="pre">www.djangoproject.com&quot;</span></tt>, the output would be
<tt class="docutils literal"><span class="pre">'Check</span> <span class="pre">out</span> <span class="pre">&lt;a</span> <span class="pre">href=&quot;http://www.djangoproject.com&quot;</span>
<span class="pre">rel=&quot;nofollow&quot;&gt;www.djangopr...&lt;/a&gt;'</span></tt>.</p>
<p>As with <a class="reference internal" href="#urlize">urlize</a>, this filter should only be applied to plain text.</p>
</div>
<div class="section" id="s-wordcount">
<span id="s-std:templatefilter-wordcount"></span><span id="wordcount"></span><span id="std:templatefilter-wordcount"></span><h3>wordcount<a class="headerlink" href="#wordcount" title="Permalink to this headline">¶</a></h3>
<p>Returns the number of words.</p>
<p>For example:</p>
<div class="highlight-html+django"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">&quot;Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug&quot;</span></tt>, the output will be <tt class="docutils literal"><span class="pre">4</span></tt>.</p>
</div>
<div class="section" id="s-wordwrap">
<span id="s-std:templatefilter-wordwrap"></span><span id="wordwrap"></span><span id="std:templatefilter-wordwrap"></span><h3>wordwrap<a class="headerlink" href="#wordwrap" title="Permalink to this headline">¶</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"><div class="highlight"><pre><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 <tt class="docutils literal"><span class="pre">value</span></tt> is <tt class="docutils literal"><span class="pre">Joel</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">slug</span></tt>, the output would be:</p>
<div class="highlight-html+django"><div class="highlight"><pre>Joel
is a
slug
</pre></div>
</div>
</div>
<div class="section" id="s-yesno">
<span id="s-std:templatefilter-yesno"></span><span id="yesno"></span><span id="std:templatefilter-yesno"></span><h3>yesno<a class="headerlink" href="#yesno" title="Permalink to this headline">¶</a></h3>
<p>Maps values for true, false and (optionally) None, to the strings &#8220;yes&#8221;, &#8220;no&#8221;,
&#8220;maybe&#8221;, 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"><div class="highlight"><pre><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">
<colgroup>
<col width="15%" />
<col width="33%" />
<col width="52%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Value</th>
<th class="head">Argument</th>
<th class="head">Outputs</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">True</span></tt></td>
<td>&nbsp;</td>
<td><tt class="docutils literal"><span class="pre">yes</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">True</span></tt></td>
<td><tt class="docutils literal"><span class="pre">&quot;yeah,no,maybe&quot;</span></tt></td>
<td><tt class="docutils literal"><span class="pre">yeah</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">False</span></tt></td>
<td><tt class="docutils literal"><span class="pre">&quot;yeah,no,maybe&quot;</span></tt></td>
<td><tt class="docutils literal"><span class="pre">no</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">None</span></tt></td>
<td><tt class="docutils literal"><span class="pre">&quot;yeah,no,maybe&quot;</span></tt></td>
<td><tt class="docutils literal"><span class="pre">maybe</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">None</span></tt></td>
<td><tt class="docutils literal"><span class="pre">&quot;yeah,no&quot;</span></tt></td>
<td><tt class="docutils literal"><span class="pre">&quot;no&quot;</span></tt> (converts None to False
if no mapping for None is given)</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="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="Permalink to this headline">¶</a></h2>
<p>Django provides template tags and filters to control each aspect of
<a class="reference internal" href="../../topics/i18n/index.html"><em>internationalization</em></a> in templates. They allow for
granular control of translations, formatting, and time zone conversions.</p>
<div class="section" id="s-i18n">
<span id="i18n"></span><h3>i18n<a class="headerlink" href="#i18n" title="Permalink to this headline">¶</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"><tt class="xref std std-setting docutils literal"><span class="pre">USE_I18N</span></tt></a> to <tt class="docutils literal"><span class="pre">True</span></tt>, then load it with
<tt class="docutils literal"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">i18n</span> <span class="pre">%}</span></tt>.</p>
<p>See <a class="reference internal" href="../../topics/i18n/translation.html#specifying-translation-strings-in-template-code"><em>Internationalization: in template code</em></a>.</p>
</div>
<div class="section" id="s-l10n">
<span id="l10n"></span><h3>l10n<a class="headerlink" href="#l10n" title="Permalink to this headline">¶</a></h3>
<p>This library provides control over the localization of values in templates.
You only need to load the library using <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">l10n</span> <span class="pre">%}</span></tt>, but you&#8217;ll often
set <a class="reference internal" href="../settings.html#std:setting-USE_L10N"><tt class="xref std std-setting docutils literal"><span class="pre">USE_L10N</span></tt></a> to <tt class="docutils literal"><span class="pre">True</span></tt> so that localization is active by default.</p>
<p>See <a class="reference internal" href="../../topics/i18n/formatting.html#topic-l10n-templates"><em>Controlling localization in templates</em></a>.</p>
</div>
<div class="section" id="s-tz">
<span id="tz"></span><h3>tz<a class="headerlink" href="#tz" title="Permalink to this headline">¶</a></h3>
<p>This library provides control over time zone conversions in templates.
Like <tt class="docutils literal"><span class="pre">l10n</span></tt>, you only need to load the library using <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">tz</span> <span class="pre">%}</span></tt>,
but you&#8217;ll usually also set <a class="reference internal" href="../settings.html#std:setting-USE_TZ"><tt class="xref std std-setting docutils literal"><span class="pre">USE_TZ</span></tt></a> to <tt class="docutils literal"><span class="pre">True</span></tt> 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"><em>Time zone aware output in templates</em></a>.</p>
</div>
</div>
<div class="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="Permalink to this headline">¶</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"><tt class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></tt></a> setting and enable in your
template with the <a class="reference internal" href="#std:templatetag-load"><tt class="xref std std-ttag docutils literal"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">%}</span></tt></a> tag.</p>
<div class="section" id="s-django-contrib-humanize">
<span id="django-contrib-humanize"></span><h3>django.contrib.humanize<a class="headerlink" href="#django-contrib-humanize" title="Permalink to this headline">¶</a></h3>
<p>A set of Django template filters useful for adding a &#8220;human touch&#8221; to data. See
<a class="reference internal" href="../contrib/humanize.html"><em>django.contrib.humanize</em></a>.</p>
</div>
<div class="section" id="s-django-contrib-webdesign">
<span id="django-contrib-webdesign"></span><h3>django.contrib.webdesign<a class="headerlink" href="#django-contrib-webdesign" title="Permalink to this headline">¶</a></h3>
<p>A collection of template tags that can be useful while designing a Web site,
such as a generator of Lorem Ipsum text. See <a class="reference internal" href="../contrib/webdesign.html"><em>django.contrib.webdesign</em></a>.</p>
</div>
<div class="section" id="s-static">
<span id="static"></span><h3>static<a class="headerlink" href="#static" title="Permalink to this headline">¶</a></h3>
<div class="section" id="s-std:templatetag-static">
<span id="s-id7"></span><span id="std:templatetag-static"></span><span id="id7"></span><h4>static<a class="headerlink" href="#std:templatetag-static" title="Permalink to this headline">¶</a></h4>
<p>To link to static files that are saved in <a class="reference internal" href="../settings.html#std:setting-STATIC_ROOT"><tt class="xref std std-setting docutils literal"><span class="pre">STATIC_ROOT</span></tt></a> Django ships
with a <a class="reference internal" href="#std:templatetag-static"><tt class="xref std std-ttag docutils literal"><span class="pre">static</span></tt></a> template tag. You can use this regardless if you&#8217;re
using <a class="reference internal" href="api.html#django.template.RequestContext" title="django.template.RequestContext"><tt class="xref py py-class docutils literal"><span class="pre">RequestContext</span></tt></a> or not.</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">load</span> <span class="nv">static</span> <span class="cp">%}</span>
<span class="nt">&lt;img</span> <span class="na">src=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">static</span> <span class="s2">&quot;images/hi.jpg&quot;</span> <span class="cp">%}</span><span class="s">&quot;</span> <span class="na">alt=</span><span class="s">&quot;Hi!&quot;</span> <span class="nt">/&gt;</span>
</pre></div>
</div>
<p>It is also able to consume standard context variables, e.g. assuming a
<tt class="docutils literal"><span class="pre">user_stylesheet</span></tt> variable is passed to the template:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">load</span> <span class="nv">static</span> <span class="cp">%}</span>
<span class="nt">&lt;link</span> <span class="na">rel=</span><span class="s">&quot;stylesheet&quot;</span> <span class="na">href=</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">type=</span><span class="s">&quot;text/css&quot;</span> <span class="na">media=</span><span class="s">&quot;screen&quot;</span> <span class="nt">/&gt;</span>
</pre></div>
</div>
<p>If you&#8217;d like to retrieve a static URL without displaying it, you can use a
slightly different call:</p>
<div class="versionadded">
<span class="title">New in Django 1.5.</span> </div>
<div class="highlight-html+django"><div class="highlight"><pre><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="nt">&lt;img</span> <span class="na">src=</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="nt">&gt;&lt;/img&gt;</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>The <a class="reference internal" href="../contrib/staticfiles.html#module-django.contrib.staticfiles" title="django.contrib.staticfiles: An app for handling static files."><tt class="xref py py-mod docutils literal"><span class="pre">staticfiles</span></tt></a> contrib app also ships
with a <a class="reference internal" href="../contrib/staticfiles.html#std:templatetag-staticfiles-static"><tt class="xref std std-ttag docutils literal"><span class="pre">static</span> <span class="pre">template</span> <span class="pre">tag</span></tt></a> which uses
<tt class="docutils literal"><span class="pre">staticfiles'</span></tt> <a class="reference internal" href="../settings.html#std:setting-STATICFILES_STORAGE"><tt class="xref std std-setting docutils literal"><span class="pre">STATICFILES_STORAGE</span></tt></a> to build the URL of the
given path (rather than simply using <tt class="xref py py-func docutils literal"><span class="pre">urlparse.urljoin()</span></tt> with the
<a class="reference internal" href="../settings.html#std:setting-STATIC_URL"><tt class="xref std std-setting docutils literal"><span class="pre">STATIC_URL</span></tt></a> setting and the given path). Use that instead if you
have an advanced use case such as <a class="reference internal" href="../../howto/static-files/deployment.html#staticfiles-from-cdn"><em>using a cloud service to serve
static files</em></a>:</p>
<div class="last highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">load</span> <span class="nv">static</span> <span class="nv">from</span> <span class="nv">staticfiles</span> <span class="cp">%}</span>
<span class="nt">&lt;img</span> <span class="na">src=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">static</span> <span class="s2">&quot;images/hi.jpg&quot;</span> <span class="cp">%}</span><span class="s">&quot;</span> <span class="na">alt=</span><span class="s">&quot;Hi!&quot;</span> <span class="nt">/&gt;</span>
</pre></div>
</div>
</div>
</div>
<div class="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>get_static_prefix<a class="headerlink" href="#get-static-prefix" title="Permalink to this headline">¶</a></h4>
<p>You should prefer the <a class="reference internal" href="#std:templatetag-static"><tt class="xref std std-ttag docutils literal"><span class="pre">static</span></tt></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"><tt class="xref std std-setting docutils literal"><span class="pre">STATIC_URL</span></tt></a> is injected into the template,
you can use the <a class="reference internal" href="#std:templatetag-get_static_prefix"><tt class="xref std std-ttag docutils literal"><span class="pre">get_static_prefix</span></tt></a> template tag:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">load</span> <span class="nv">static</span> <span class="cp">%}</span>
<span class="nt">&lt;img</span> <span class="na">src=</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="s">&quot;Hi!&quot;</span> <span class="nt">/&gt;</span>
</pre></div>
</div>
<p>There&#8217;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"><div class="highlight"><pre><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="nt">&lt;img</span> <span class="na">src=</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="s">&quot;Hi!&quot;</span> <span class="nt">/&gt;</span>
<span class="nt">&lt;img</span> <span class="na">src=</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="s">&quot;Hello!&quot;</span> <span class="nt">/&gt;</span>
</pre></div>
</div>
</div>
<div class="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>get_media_prefix<a class="headerlink" href="#get-media-prefix" title="Permalink to this headline">¶</a></h4>
<p>Similar to the <a class="reference internal" href="#std:templatetag-get_static_prefix"><tt class="xref std std-ttag docutils literal"><span class="pre">get_static_prefix</span></tt></a>, <tt class="docutils literal"><span class="pre">get_media_prefix</span></tt> populates a
template variable with the media prefix <a class="reference internal" href="../settings.html#std:setting-MEDIA_URL"><tt class="xref std std-setting docutils literal"><span class="pre">MEDIA_URL</span></tt></a>, e.g.:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="nt">&lt;script </span><span class="na">type=</span><span class="s">&quot;text/javascript&quot;</span> <span class="na">charset=</span><span class="s">&quot;utf-8&quot;</span><span class="nt">&gt;</span>
<span class="kd">var</span> <span class="nx">media_path</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="cp">{%</span> <span class="k">get_media_prefix</span> <span class="cp">%}</span><span class="s1">&#39;</span><span class="p">;</span>
<span class="nt">&lt;/script&gt;</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>


          </div>         
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <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">autoescape</a></li>
<li><a class="reference internal" href="#block">block</a></li>
<li><a class="reference internal" href="#comment">comment</a></li>
<li><a class="reference internal" href="#csrf-token">csrf_token</a></li>
<li><a class="reference internal" href="#cycle">cycle</a></li>
<li><a class="reference internal" href="#debug">debug</a></li>
<li><a class="reference internal" href="#extends">extends</a></li>
<li><a class="reference internal" href="#filter">filter</a></li>
<li><a class="reference internal" href="#firstof">firstof</a></li>
<li><a class="reference internal" href="#for">for</a></li>
<li><a class="reference internal" href="#for-empty">for ... empty</a></li>
<li><a class="reference internal" href="#if">if</a></li>
<li><a class="reference internal" href="#boolean-operators">Boolean operators</a></li>
<li><a class="reference internal" href="#operator"><tt class="docutils literal"><span class="pre">==</span></tt> operator</a></li>
<li><a class="reference internal" href="#id1"><tt class="docutils literal"><span class="pre">!=</span></tt> operator</a></li>
<li><a class="reference internal" href="#id2"><tt class="docutils literal"><span class="pre">&lt;</span></tt> operator</a></li>
<li><a class="reference internal" href="#id3"><tt class="docutils literal"><span class="pre">&gt;</span></tt> operator</a></li>
<li><a class="reference internal" href="#id4"><tt class="docutils literal"><span class="pre">&lt;=</span></tt> operator</a></li>
<li><a class="reference internal" href="#id5"><tt class="docutils literal"><span class="pre">&gt;=</span></tt> operator</a></li>
<li><a class="reference internal" href="#in-operator"><tt class="docutils literal"><span class="pre">in</span></tt> operator</a></li>
<li><a class="reference internal" href="#not-in-operator"><tt class="docutils literal"><span class="pre">not</span> <span class="pre">in</span></tt> operator</a></li>
<li><a class="reference internal" href="#filters">Filters</a></li>
<li><a class="reference internal" href="#complex-expressions">Complex expressions</a></li>
<li><a class="reference internal" href="#ifchanged">ifchanged</a></li>
<li><a class="reference internal" href="#ifequal">ifequal</a></li>
<li><a class="reference internal" href="#ifnotequal">ifnotequal</a></li>
<li><a class="reference internal" href="#include">include</a></li>
<li><a class="reference internal" href="#load">load</a></li>
<li><a class="reference internal" href="#now">now</a></li>
<li><a class="reference internal" href="#regroup">regroup</a></li>
<li><a class="reference internal" href="#grouping-on-other-properties">Grouping on other properties</a></li>
<li><a class="reference internal" href="#spaceless">spaceless</a></li>
<li><a class="reference internal" href="#ssi">ssi</a></li>
<li><a class="reference internal" href="#templatetag">templatetag</a></li>
<li><a class="reference internal" href="#url">url</a></li>
<li><a class="reference internal" href="#verbatim">verbatim</a></li>
<li><a class="reference internal" href="#widthratio">widthratio</a></li>
<li><a class="reference internal" href="#with">with</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">add</a></li>
<li><a class="reference internal" href="#addslashes">addslashes</a></li>
<li><a class="reference internal" href="#capfirst">capfirst</a></li>
<li><a class="reference internal" href="#center">center</a></li>
<li><a class="reference internal" href="#cut">cut</a></li>
<li><a class="reference internal" href="#date">date</a></li>
<li><a class="reference internal" href="#default">default</a></li>
<li><a class="reference internal" href="#default-if-none">default_if_none</a></li>
<li><a class="reference internal" href="#dictsort">dictsort</a></li>
<li><a class="reference internal" href="#dictsortreversed">dictsortreversed</a></li>
<li><a class="reference internal" href="#divisibleby">divisibleby</a></li>
<li><a class="reference internal" href="#escape">escape</a></li>
<li><a class="reference internal" href="#escapejs">escapejs</a></li>
<li><a class="reference internal" href="#filesizeformat">filesizeformat</a></li>
<li><a class="reference internal" href="#first">first</a></li>
<li><a class="reference internal" href="#fix-ampersands">fix_ampersands</a></li>
<li><a class="reference internal" href="#floatformat">floatformat</a></li>
<li><a class="reference internal" href="#force-escape">force_escape</a></li>
<li><a class="reference internal" href="#get-digit">get_digit</a></li>
<li><a class="reference internal" href="#iriencode">iriencode</a></li>
<li><a class="reference internal" href="#join">join</a></li>
<li><a class="reference internal" href="#last">last</a></li>
<li><a class="reference internal" href="#length">length</a></li>
<li><a class="reference internal" href="#length-is">length_is</a></li>
<li><a class="reference internal" href="#linebreaks">linebreaks</a></li>
<li><a class="reference internal" href="#linebreaksbr">linebreaksbr</a></li>
<li><a class="reference internal" href="#linenumbers">linenumbers</a></li>
<li><a class="reference internal" href="#ljust">ljust</a></li>
<li><a class="reference internal" href="#lower">lower</a></li>
<li><a class="reference internal" href="#make-list">make_list</a></li>
<li><a class="reference internal" href="#phone2numeric">phone2numeric</a></li>
<li><a class="reference internal" href="#pluralize">pluralize</a></li>
<li><a class="reference internal" href="#pprint">pprint</a></li>
<li><a class="reference internal" href="#random">random</a></li>
<li><a class="reference internal" href="#removetags">removetags</a></li>
<li><a class="reference internal" href="#rjust">rjust</a></li>
<li><a class="reference internal" href="#safe">safe</a></li>
<li><a class="reference internal" href="#safeseq">safeseq</a></li>
<li><a class="reference internal" href="#slice">slice</a></li>
<li><a class="reference internal" href="#slugify">slugify</a></li>
<li><a class="reference internal" href="#stringformat">stringformat</a></li>
<li><a class="reference internal" href="#striptags">striptags</a></li>
<li><a class="reference internal" href="#time">time</a></li>
<li><a class="reference internal" href="#timesince">timesince</a></li>
<li><a class="reference internal" href="#timeuntil">timeuntil</a></li>
<li><a class="reference internal" href="#title">title</a></li>
<li><a class="reference internal" href="#truncatechars">truncatechars</a></li>
<li><a class="reference internal" href="#truncatewords">truncatewords</a></li>
<li><a class="reference internal" href="#truncatewords-html">truncatewords_html</a></li>
<li><a class="reference internal" href="#unordered-list">unordered_list</a></li>
<li><a class="reference internal" href="#upper">upper</a></li>
<li><a class="reference internal" href="#urlencode">urlencode</a></li>
<li><a class="reference internal" href="#urlize">urlize</a></li>
<li><a class="reference internal" href="#urlizetrunc">urlizetrunc</a></li>
<li><a class="reference internal" href="#wordcount">wordcount</a></li>
<li><a class="reference internal" href="#wordwrap">wordwrap</a></li>
<li><a class="reference internal" href="#yesno">yesno</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">i18n</a></li>
<li><a class="reference internal" href="#l10n">l10n</a></li>
<li><a class="reference internal" href="#tz">tz</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">django.contrib.humanize</a></li>
<li><a class="reference internal" href="#django-contrib-webdesign">django.contrib.webdesign</a></li>
<li><a class="reference internal" href="#static">static</a><ul>
<li><a class="reference internal" href="#std:templatetag-static">static</a></li>
<li><a class="reference internal" href="#get-static-prefix">get_static_prefix</a></li>
<li><a class="reference internal" href="#get-media-prefix">get_media_prefix</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="index.html">Templates</a></li>
    
    
      <li>Next: <a href="api.html">The Django template language: For Python programmers</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../index.html">Django 1.6.7 documentation</a>
        
          <ul><li><a href="../index.html">API Reference</a>
        
          <ul><li><a href="index.html">Templates</a>
        
        <ul><li>Built-in template tags and filters</li></ul>
        </li></ul></li></ul>
      </li>
  </ul>  

  <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 id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Sep 26, 2014</p>
          </div> 
        
      
    </div>
    
    <div id="ft">
      <div class="nav">
    &laquo; <a href="index.html" title="Templates">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>