1

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.

1 Answer 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.)

Sign up to request clarification or add additional context in comments.

1 Comment

Oh haha thanks that explain.. btw i not doing any project or so just trying out Django. So that why i dont mind displaying the password while u dont do it .In the industry .