Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - Redirect with context

I have a Sign Up page which takes a user's username and password and saves it in the database. If the user is successfully signed up, I want to redirect him to a 'Sign In' page, with a value denoting that Signup was successful.

Expected output on the redirected page:

You have been successfully signed up.

Sign In

Username: ---

Password: ---

So, I am redirecting from the signup to the signin page, but I want to pass a value showing that the user has come from the Signup page and is successfully signed up.

How do I perform this?

like image 356
xennygrimmato Avatar asked Dec 01 '22 00:12

xennygrimmato


1 Answers

Use the messages framework to add a message in the first view and display it in the second one.

Or simply put an item in the session, and pop it out again:

request.session['signup'] = True
return redirect('wherever')

...

signup = request.session.pop('signup', False)
if signup:
    ... do something ...
like image 160
Daniel Roseman Avatar answered Dec 05 '22 10:12

Daniel Roseman