Logged in users still see login page (django auth)
You hide content within the template.html
using templateTags
like so:
{% if user.is_authenticated %}
<p>Only a logged in User can view</p>
{% else %}
<p>Only a logged out User can view</p>
{% endif %}
[EDIT]
If you would like to then redirect the user before the web page is rendered, then you can do that in the view.
def myView(request):
if request.user.is_authenticated:
return render(request, 'logged_in_view.html')
else:
return render(request, 'logged_out_view.html')
Possible solution: I create 'my_login':
def my_login(request):
if request.user.is_authenticated():
return redirect(#...home)
else:
return login(request, 'template/login.html') # here i used login built-in function
# instead of using directly in urls.py
And i used my_login
view in urls.py instead of 'django.contrib.auth.views.login'
EDIT
New in Django 1.10:
The redirect_authenticated_user parameter was added.
Check https://docs.djangoproject.com/en/1.10/topics/auth/default/#django.contrib.auth.views.login
Simply you can write you login url as this:
from django.contrib.auth import views as auth_views
path('login/', auth_views.LoginView.as_view(template_name="accounts/login.html", redirect_authenticated_user=True), name='login'),