python - Checking if authenticated in Django template inheritance -
python - Checking if authenticated in Django template inheritance -
i have next code in template , having difficulty showing when user logged in. able login, when revisit page, shows i'm still not authenticated.
{% extends "base.html" %} {% load catalog_tags %} {% block site_wrapper %} <div id = "main"> <a href="#content" class="skip_link">skip main content</a> <div id = "banner"> <div class="banneriepadder"> <div class="cart_box"> {% cart_box request %} </div> </div> </div> <div style="float:right;">[search box goes here]</div> <div id="navigation"> <div class="naviepadder"> <!--navigation tabs @ top of each page --> {% comment %}{% include "tags/navigation.html" %} {% endcomment %} {% category_list request.path %} </div> </div> <div id="middle"> <div id="sidebar"> <!--<div class="sidebariepadder">[search box goes here]</br> {% comment %}{% category_list request.path %}{% endcomment %} </div>--> </div> <div id="content"> <!-- <a name = "content"></a>--> <div class="contentiepadder"> {% block content %}{% endblock %} </div> </div> </div> <div id="footer"> <div class="footeriepadder"> {% footer_links %} </div> </div> </div> {% endblock %} and here's file references. since extension of templates, there need consider?
###category_list.html <!--<h3>categories</h3>--> <!--<ul id="categories">--> <ul> {% active_categories cats %} {% c in cats %} <li> {% comment %} {% ifequal c.get_absolute_url request_path %} {{c.name}} {% else %} {% endcomment %} <div><a href="{{c.get_absolute_url}}" class="category">{{c.name}}</a></div> {% comment %}{% endifequal %}{% endcomment %} </li> {% endfor %} <div class="fr"> <ul> <li> {% if user.is_authenticated %} <a href = "{% url django.contrib.auth.views.logout %}">logout</a> {% else %} <a href = "{% url django.contrib.auth.views.login %}">login</a> {% endif %} </li> </div> {% endwith %} </ul> <div class="cb"></div> am missing here?
you need pass requestcontext template. easiest way import django.shortcuts , utilize render method in view:
return render(request, "my_template.html") python django
Comments
Post a Comment