title: Changing the active class of a link with the twitter bootstrap css in python/flask
body: <p>I got the following html snippet from my page <code>template.html</code>.</p>
  
  <pre><code>&lt;ul class='nav'&gt;
      &lt;li class="active"&gt;&lt;a href='/'&gt;Home&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href='/lorem'&gt;Lorem&lt;/a&gt;&lt;/li&gt;
  
      {% if session['logged_in'] %}
          &lt;li&gt;&lt;a href="/account"&gt;Account&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="/projects"&gt;Projects&lt;/a&gt;
          &lt;li&gt;&lt;a href="/logout"&gt;Logout&lt;/a&gt;&lt;/li&gt;
      {% endif %}
  
      {% if not session['logged_in'] %}
          &lt;li&gt;&lt;a href="/login"&gt;Login&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="/register"&gt;Register&lt;/a&gt;&lt;/li&gt;
      {% endif %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>As you can see on line 2, there's the class active. This highlights the active tab with the twitter bootstrap css file. Now, this will work fine if I would visit <code>www.page.com/</code> but not when I would visit <code>www.page.com/login</code> for example. It would still highlight the home link as the active tab.</p>
  
  <p>Of course, I could easily do this with Javascript/jQuery but I'd rather not use that in this situation.</p>
  
  <p>There's already a <a href="https://stackoverflow.com/questions/9879169/how-to-get-twitter-bootstrap-navigation-to-show-active-link">working solution for ruby on rails</a> but I don't know how to convert that into python/jinja (I'm rather new to jinja/flask, never worked with ruby at all)</p>