Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8579409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:36:12+00:00 2026-06-11T20:36:12+00:00

I am implementing a basic login and logout page using django. My login function

  • 0

I am implementing a basic login and logout page using django. My login function adds a row into the django_session table in db. However, when I logout, it doesn’t remove the session row. Since the session is no longer valid and all the session related data is removed from the request, shouldn’t the logout function also remove the session row from the django_session table?

Here is my logout function:

@login_required
def logout_student(request):
    logout(request)
    # Redirect to a success page.
    return HttpResponseRedirect('/index/')

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:36:12+00:00Added an answer on June 11, 2026 at 8:36 pm

    If you manually adds a row to django_session on login, then on django.contrib.auth.logout(), the request.session.flush()) function will only delete the row with the same primary key session_key as the current session key from django_session table.

    request.session.flush() is used to ensure that the previous session data can’t be accessed again from the user’s browser. It basically does two things:

    1. delete the current session data from the database (or cache, depends on which one you choose for your session backends).
    2. regenerate the session key value that is sent back to the user in the cookie.

    The Django source code of django.contrib.auth.logout():

    def logout(request):
        """
        Removes the authenticated user's ID from the request and flushes their
        session data.
        """
        # Dispatch the signal before the user is logged out so the receivers have a
        # chance to find out *who* logged out.
        user = getattr(request, 'user', None)
        if hasattr(user, 'is_authenticated') and not user.is_authenticated():
            user = None
        user_logged_out.send(sender=user.__class__, request=request, user=user)
    
        request.session.flush()
        if hasattr(request, 'user'):
            from django.contrib.auth.models import AnonymousUser
            request.user = AnonymousUser()
    

    Delete method for database-based session:

    def delete(self, session_key=None):
        if session_key is None:
            if self.session_key is None:
                return
            session_key = self.session_key
        try:
            Session.objects.get(session_key=session_key).delete()
        except Session.DoesNotExist:
            pass
    

    To remove the manually added row, you can utilize Django signal django.contrib.auth.signals.user_logged_out to delete row on user logout.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used this tutorial to create a basic Javascript function for implementing change during
For a particular piece of homework, I'm implementing a basic data storage system using
I am implementing a really basic server-client model in Java, by using UDP sockets
Implementing the basic algorithm using last array as a pivot in Java, is it
I'm looking at a tutorial for asp.net mvc here on the asp site: http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-application
We are working implementing Single Sign On(SSO) using pingfederate . The basic implementation uses
I've spent two days trying to make a login/logout panel in PHP. I'm using
I am implementing a basic authentication WCF service in ASP.NET using Visual Studio 2010.
I am currently implementing a basic raytracer in c++. Works pretty well so far,
I am implementing a basic board game in Java and that I am having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.