Use Python `set` keyword in Jinja
<p>I want to return unique items in Jinja template. Simplified:</p>

<pre><code>{% set lst = [1, 2, 3, 3, 2] %}
{% for t in set(lst) %}
    {{ t }}
{% endfor %}
</code></pre>

<p>But this throws error:</p>

<pre><code>UndefinedError: 'set' is undefined
</code></pre>

<p>And it seems hard to find answer on Google as <code>set</code> is also Jinja keyword.
So can I use Python's <code>set</code> keyword in Jinja, or can I return unique items from list in Jinja?</p>

<p>What set does is create a variable, so when you are using <code>set lst = 1</code>, you then access it with <code>lst</code>, not <code>set(lst)</code></p>

<p>edit: misunderstood question, to access a python function from jinja, here's what I do in my flask app</p>

<pre><code>@app.context_processor
def inject_python():
    return dict(set=set)
</code></pre>

<p>This way, jinja will have the function and you can use it as you did</p>

python jinja2