问题描述
我有一个注册页面,它接受用户的用户名和密码并将其保存在数据库中。如果用户注册成功,我想将其重定向到登录页面,其值指示注册成功。重定向的预期输出页面:
您已成功注册。
在
用户名:---
密码:---
所以,我正在从注册页面重定向到登录页面,但是我想传递一个值,显示用户已经来
$ b
如何执行此操作?
使用在第一个视图中添加消息,在第二个中显示它。
或者简单地在会话中放入一个项目,然后再次弹出:
request.session ['signup'] = True
retu rn redirect('wherever')
...
signup = request.session.pop('signup',False)
如果注册:
...做某事...
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?
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 ...
这篇关于Django - 重定向与上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!