You might want to use the Django Sessions middleware, which will set a cookie with django session_id. For the following requests, the session middleware will set the attribute of the request object called by the user, and then you can check if the user is authenticated request.user.is_authenticated () (or login_required decorator). In addition, you can set the session timeout to anything you like in the settings.
This middleware is included in django's default settings.
source share