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

394 views
Skip to first unread message

isha thakur

unread,
Jul 28, 2020, 6:08:22 PM7/28/20
to Django users
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

jhabar singh

unread,
Jul 29, 2020, 12:22:00 AM7/29/20
to django...@googlegroups.com
by the way how can django logout automatically. I mean user should only be given the access to do so. 

--
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...@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.

Isha Thakur

unread,
Jul 29, 2020, 2:12:29 PM7/29/20
to django...@googlegroups.com
I mean, suppose I logged in, accessed my website, and closed the browser. Sometimes when I try to access my website next time the session is closed(logout). This does not happen all the time it happens once in a month.

When I do log out manually(I mean when I click on the logout button on my website) and login back then I ma not facing any issue.

Regards
Isha

From: django...@googlegroups.com <django...@googlegroups.com> on behalf of jhabar singh <jhabarsing...@gmail.com>
Sent: July 29, 2020 12:20 AM
To: django...@googlegroups.com <django...@googlegroups.com>
Subject: Re: Django automatic Logout and and after login it stays on same page
 
NOTICE:This email and any files transmitted with it are Enablence confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender. This message contains Enablence confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

Isha Thakur

unread,
Jul 30, 2020, 12:12:50 PM7/30/20
to django...@googlegroups.com
Please help me if someone facing the same issue.

Regards
Isha

From: django...@googlegroups.com <django...@googlegroups.com> on behalf of Isha Thakur <Isha....@enablence.com>
Sent: July 29, 2020 1:28 PM
Reply all
Reply to author
Forward
0 new messages