我想允许用户更改密码,我正在使用django-in-built password_change函数。我想使用默认的template-name和password_change_form,但我想将post_change_redirect参数更改为特定于我的网站。
如何在保持其余部分相同的情况下改变它?
来自Django文档:
password_change(request[, template_name, post_change_redirect, password_change_form])
Allows a user to change their password.
URL name: password_change
Optional arguments:
template_name: The full name of a template to use for displaying the password change form. Defaults to registration/password_change_form.html if not supplied.
post_change_redirect: The URL to redirect to after a successful password change.
password_change_form: A custom "change password" form which must accept a user keyword argument. The form is responsible for actually changing the user's password. Defaults to PasswordChangeForm.
Template context:
form:密码更改表单(参见上面的password_change_form)。
需要一些指导。感谢。
答案 0 :(得分:3)
您想要定义一个视图,该视图将提供修改后的password_change
视图:
from django.contrib.auth.views import password_change
def change_password(request):
return password_change(request, post_change_redirect='%my_post_change_url%')
就是这样。
您必须记住,如果您没有登录,它会将您重定向到默认登录页面,并且您必须编写密码更改页面模板(默认情况下名为registration/password_change_form.html
)< / p>