1

ユーザーがパスワードを変更できるようにしたいのですが、django-in-built password_change 関数を使用しています。デフォルトの template-name と password_change_form を使用したいのですが、post_change_redirect 引数を自分の Web サイトに固有のものに変更したいと考えています。

残りを同じに保ちながら、それだけを変更するにはどうすればよいですか?

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 に答える