How do I only show certain items in a bootstrap navbar based on cookies in Python? -
my bootstrap navbar in base template , looks this:
<ul class="nav navbar-nav"> <li><a href="/">home</a></li> <li><a href="/about">about</a></li> <li><a href="/post">new post</a></li> <li><a href="/login">login</a></li> <li><a href="/logout">logout</a></li> <li><a href="/register">register</a></li> </ul>
i want make navbar hide new post , logout list items when user not signed in, , hide login , register list items when is. tips on how make possible?
if helps, i'm using python 2.7 jinja2 , i'm authenticating users cookie.
you use this:
{% if user %} <ul class="nav navbar-nav"> <li><a href="/">home</a></li> <li><a href="/about">about</a></li> <li><a href="/post">new post</a></li> <li><a href="/logout">logout</a></li> </ul> {% elif not user %} <ul class="nav navbar-nav"> <li><a href="/">home</a></li> <li><a href="/about">about</a></li> <li><a href="/login">login</a></li> <li><a href="/register">register</a></li> </ul> {% endif %}
supposing you're passing template variable user
depends on presence or absence of cookie. have verify first in view if cookie set , pass result template.
Comments
Post a Comment