'Django retrieve sessionID created with Login
I am using Django 1.9. Base on the Django documentation:
" To log a user in, from a view, use login(). It takes an HttpRequest object and a User object. login() saves the user’s ID in the session, using Django’s session framework."
So how do I retrieve the information in that session.
For example: (this is also taken from the documentation)
from django.contrib.auth import authenticate, login
def my_view(request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
**login(request, user)**
# Redirect to a success page.
else:
How do I retrieve the user information such as username or if possible the password out on the success page.
P.S If you could also kinda explain the solution in layman term as possible
EDIT I was playing around with the framework back then. So I was testing if it can be done.
Solution 1:[1]
You don't get it from the session.
The authentication middleware adds the current user to the request, as request.user
.
(And you definitely do not ever retrieve or display the password.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Daniel Roseman |