如何在Django 1.9中实现密码更改表单 [英] How to implement password change form in Django 1.9
问题描述
我的python项目的网址在这里:
https://github.com/abylikhsanov/social
The url for my python project is here: https://github.com/abylikhsanov/social
我正在尝试实施密码更改表单,因此用户可以更改其密码。如何实现?应用程序应该跟踪以前的密码,不应该允许用户使用以前使用的密码。另外,我想实现重置密码功能。
I am trying to implement the password change form, so the user can change his or her password. How can I implement it? The application should keep track of the previous password and should not allow the user to use a previously used password. Also, I want to implement the reset password function.
推荐答案
为什么不使用django的内置PasswordChangeForm(django.contrib.auth.forms)。
why don't you use django's built-in PasswordChangeForm (django.contrib.auth.forms).
如果你喜欢它的工作方式,只需使用这个,或者你可以创建一个继承PasswordChangeForm的新的
If you like the way it works just use this from, or you can create a new one that inherits PasswordChangeForm
class PasswordChangeCustomForm(PasswordChangeForm):
error_css_class = 'has-error'
error_messages = {'password_incorrect':
"Το παλιό συνθηματικό δεν είναι σωστό. Προσπαθείστε ξανά."}
old_password = CharField(required=True, label='Συνθηματικό',
widget=PasswordInput(attrs={
'class': 'form-control'}),
error_messages={
'required': 'Το συνθηματικό δε μπορεί να είναι κενό'})
new_password1 = CharField(required=True, label='Συνθηματικό',
widget=PasswordInput(attrs={
'class': 'form-control'}),
error_messages={
'required': 'Το συνθηματικό δε μπορεί να είναι κενό'})
new_password2 = CharField(required=True, label='Συνθηματικό (Επαναλάβατε)',
widget=PasswordInput(attrs={
'class': 'form-control'}),
error_messages={
'required': 'Το συνθηματικό δε μπορεί να είναι κενό'})
我稍后将提供清洁和保存方法的示例
I will provide later an example of the clean and save methods
请参阅这里了解更多细节
这篇关于如何在Django 1.9中实现密码更改表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!