2012-06-28 32 views
1

我想允许用户更改密码,并且我正在使用django-in-built password_change函数。我想使用默认的模板名称和password_change_form,但我想将post_change_redirect参数更改为特定于我的网站。Django用户认证中的password_change函数

只有在保持其余部分不变的情况下,我该如何改变它?

从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: 

形式:密码变化形式(见password_change_form上文)。

需要一些指导。谢谢。

+0

' password_change(request,post_change_redirect ='my_url')'? –

+0

def lmlogout(请求): “”“ 注销视图 ”“” 返回password_change(request,post_change_redirect ='my_url')正确的用法? – lakesh

+0

最好在Django中尝试它,但这就是我将如何使用该功能。 –

回答

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