I am displaying same home page for both logged-in users and logged-out users. But the change is in navbar. Upon login there will be name of the user displayed. And upon logout nothing will be displayed. If I logout and click back button I see the back previous page getting displayed (i.e the one with the user name). I searched a bit about it and found even few questions about it.
But there decorators are used to prevent logged out users to to come back. SO that that page will get prevented from loading again. But here as I am displaying the same page for both the users, how to accomplish it ?? How to prevent navbar from showing user name of users upon logout and clicking back button.
My navbar code::
{% if request.user.is_authenticated %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ request.user.username }}</a>
<ul class="dropdown-menu" role="menu">
<li><a href="{% url 'profile' request.user.username %}">Profile</a></li>
<li><a href="{% url 'logout' %}">Logout</a></li>
{% else %} {% ifequal request.path '/accounts/login/' %}
<li><a href="{% url 'signup' %}">Sign Up</a></li>
{% else %}
<li><a href="{% url 'login' %}">Login</a></li>
{% endifequal %}
</ul>
</li>
{% endif %}
UPDATE:
My home page view is
class HomeView(TemplateView):
template_name = "home/home.html" # same template for login and logout
urls.py is
urlpatterns = [
url(r'^$', HomeView.as_view(), name="home"),
]
I am using django.contrib.auth.urls
for both login and logout operations
Thanks in advance!