how to manage sessions in django after the user is logged in (without using default admin )?

StackOverflow https://stackoverflow.com/questions/13542121

  •  01-12-2021
  •  | 
  •  

Question

I build a forum in Django i want to manage user sessions when the user post something n check comments on their own posts. Also the particular user should get notifications regarding any activity on their posts.

Was it helpful?

Solution

Django sessions are not tied to the admin. They are enabled by default. They are are provided by a middleware.

The django.contrib.sessions.middleware.SessionMiddleware middleware will populate request.session and request.user on any requests made to your app.

If the user is logged in request.user will be the corresponding User object, otherwise it will be an AnonymousUser instance.

You can find more information in the django documentation. This page includes the different configuration options, but you should be able to make do with the defaults.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top