title: Sort list of objects with Jinja2 and Flask depending the field pressed
body: <p>I have a model in Flask called Dog, with the parameters Name, Breed and Age. Through Jinja2 I show them in a template as follow:</p>
  
  <pre><code>&lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt;Name&lt;/td&gt;
  &lt;td&gt;Breed&lt;/td&gt;
  &lt;td&gt;Age&lt;/td&gt;
  &lt;/tr&gt;
  {% for dog in dogs_list %}
  &lt;tr&gt;
  &lt;td&gt;{{ dog.name }}&lt;/td&gt;
  &lt;td&gt;{{ dog.breed }}&lt;/td&gt;
  &lt;td&gt;{{ dog.age }}&lt;/td&gt;
  &lt;/tr&gt;
  {% endfor %}
  &lt;/table&gt;
  </code></pre>
  
  <p>My idea is, if the user press Name, the table show the objects sorted by Name. The same with Breed and Age. There is a filter in Jinja to order by a parameter, for example "name":</p>
  
  <pre><code>{% for dog in dogs_list|sort(attribute='name') %}
  </code></pre>
  
  <p>But I do not want to put a fixed attribute, it should change to "breed" or "age". Can I do it just with Jinja2? Should I use also Flask? Can I set values in Jinja2 with JavaScript?</p>
  
  <p>Thanks!</p>