Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

636
Views
End Session When browser is closed in python django and javascript

I have created logout def in python, in that def I am deleting session that I have created after login the user.

I wish to end/del session when the user closes the browser using(X) OR using(alt+4).

how do I call logout url in javascript when user close the browser.

Here is def logout:

@login_required
def logout(request):
    username = request.session['username']
    ip = settings.IP
    headers = settings.HEADERS
    del request.session['username']

Here is urls.py

from django.urls import path
from . import views

urlpatterns = [
    path('logout', views.logout, name="logout"),
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just set the SESSION_EXPIRE_AT_BROWSER_CLOSE setting to true, so that Django's session cookies are only valid for the length of the browser session.

If SESSION_EXPIRE_AT_BROWSER_CLOSE is set to True, Django will use browser-length cookies – cookies that expire as soon as the user closes their browser.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!