Tuesday, July 28, 2020

Django automatic Logout and and after login it stays on same page

I am new to Django and using Django 3.0.2. Sometimes Django automatically logout and when I try to log in on my website then it stays on the login page but creates a session(I mean, I can see all the buttons which a user will see after login in header and footer). I am not experiencing this issue when I am manually logging out and logging in.Please help if someone else is also experiencing the same issue. Thanks in advance. Please check my code below:

setting.py: 

LOGIN_REDIRECT_URL = 'index_login'

LOGIN_URL = 'login' 


urls.py: 


url(r'^login$',auth_views.LoginView.as_view(redirect_authenticated_user=True),name='login'), url(r'^index_login', views.index_login, name='index_login')

view.py:


@login_required
def index_login(request):
# this view is created solely for the purpose of being able to log the login information through logToDb
ut.logToDb(database, messages=['Successful login.'], user=request.user)
ut.log_info('Successful login by ' + str(request.user) + '.')
context = {'user': request.user}
return render(request, 'mainapp/index.html', context)

index.html:
 {% extends 'mainapp/base.html' %} 
{% load static %} {% block content %}
 <h3>Databases</h3> <br/><br/> 
<div class="fluid-container">
 <div class="col-md-4"> <a class="btn btn-primary btn-block btn-vspace" type="button" href="plc/index">Inventory</a> </div>
 </div>
 <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
 {% endblock %}

I am facing this problem only if Django logout automatically. But if I logout and login then I am not having issue so It is really tricky for me to generate the exact scenario

Regards
Isha

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2392d64f-0110-4fe2-a5ec-5af27c561a6ao%40googlegroups.com.

No comments:

Post a Comment