Django - Redirect with context

[亡魂溺海] 提交于 2019-12-06 04:22:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!