1

我想允许用户更改密码,我正在使用 django-in-built password_change 函数。我想使用默认的模板名称和密码更改表单,但我想将 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)。

需要一些指导。谢谢。

4

1 回答 1

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默认命名)

于 2012-06-28T09:29:56.633 回答