Design a site like this with
Get started

View Session information

Lets see how to view session information in django

From our previous tutorial, we now know how to setup authentication. We know how to create an admin user or a normal user. here is the git link if you have not gone through the tutorial already.

We are going to build on from the previous tutorial –

You can start directly from this tutorial, just copy the contents from the git repo “pip install -r requirements.txt”

Step 1 – We will now create an app to view session information. lets call this app “admin-data-viewer”. Execute below command

python startapp AdminModels

Register the app into the project under the INSTALLED_APPS object

Step 2 – This will create a new app with inside the app.

from django.contrib import admin
from django.contrib.sessions.models import Session

class SessionAdmin(admin.ModelAdmin):
    def _session_data(self, obj):
        return obj.get_decoded()
    list_display = ['session_key', '_session_data', 'expire_date'],SessionAdmin)

Step 3 – If you have not created a user, lets create a super user. Execute below command and follow instructions

python createsuperuser

Step 4 – execute makemigrations and migrate

python makemigrations
python migrate

Step 5 – Run the server

python runserver

Step 6 – Navigate to” and provide the admin username and password created in step 3 and look for b

Click on sessions to see below information about session


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: