Flask: current page in request variable

atp picture atp · Dec 30, 2011 · Viewed 40.6k times · Source

In a template, how do I get what page I'm currently on? I'd rather not pass a variable like page , especially when I know some request.xxx can provide me with the information.

<li {% if page=="home" %}class="active"{% endif %}>                   
    <a href="/">Home</a>                                                
</li>                                                                 
<li {% if page=="about" %}class="active"{% endif %}>                  
    <a href="/about">About</a>                                          
</li> 

Answer

ranksrejoined picture ranksrejoined · Dec 30, 2011

As long as you've imported request, request.path should contain this information.