问题
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?
回答1:
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 ...
来源:https://stackoverflow.com/questions/29673537/django-redirect-with-context