Python 如何删除“;“未设置密码”;在我的Django模板上编辑配置文件
在我的Django模板上,当用户登录并编辑配置文件时,我看到一条奇怪的消息,上面写着“未设置密码。未存储原始密码,因此无法查看此用户的密码,但您可以使用此表单更改密码。” 如何防止此内容显示在我的模板上?Python 如何删除“;“未设置密码”;在我的Django模板上编辑配置文件,python,django,Python,Django,在我的Django模板上,当用户登录并编辑配置文件时,我看到一条奇怪的消息,上面写着“未设置密码。未存储原始密码,因此无法查看此用户的密码,但您可以使用此表单更改密码。” 如何防止此内容显示在我的模板上? 下面是我的代码 forms.py class EditProfileForm(UserChangeForm): member_id = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control', 'plac
下面是我的代码
forms.py
class EditProfileForm(UserChangeForm):
member_id = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control', 'placeholder':'Member Id'}))
first_name = forms.CharField(label='Firstname', required=False, widget=forms.TextInput(attrs={'class':'form-control', 'placeholder':'Firstname'}))
last_name = forms.CharField(label='Lastname', required=False, widget=forms.TextInput(attrs={'class':'form-control', 'placeholder':'Lastname'}))
email = forms.CharField(label='Email*', widget=forms.EmailInput(attrs={'class':'form-control', 'placeholder':'Email'}))
phone1 = forms.CharField(label='Phone Number 1*', widget=forms.TextInput(attrs={'class':'form-control', 'placeholder':'Phone Number 1'}))
phone2 = forms.CharField(label='Phone Number 2', required=False, widget=forms.TextInput(attrs={'class':'form-control', 'placeholder':'Phone Number 2'}))
class Meta():
model = User
fields = ('member_id', 'first_name', 'last_name', 'email', 'phone1', 'phone2')
这是表单字段帮助文本
class UserChangeForm(forms.ModelForm):
password = ReadOnlyPasswordHashField(label=_("Password"),
help_text=_("Raw passwords are not stored, so there is no way to see "
"this user's password, but you can change the password "
"using <a href=\"password/\">this form</a>."))
class Meta:
help_texts = {
'password ': _(''),
}
此外,在您的情况下,将UserChangeForm子类化也没有多大意义这是表单字段帮助文本
class UserChangeForm(forms.ModelForm):
password = ReadOnlyPasswordHashField(label=_("Password"),
help_text=_("Raw passwords are not stored, so there is no way to see "
"this user's password, but you can change the password "
"using <a href=\"password/\">this form</a>."))
class Meta:
help_texts = {
'password ': _(''),
}
另外,在您的情况下,将UserChangeForm子类化也没有多大意义如果您不想使用
UserChangeForm
的密码行为,那么我会将forms.ModelForm
子类化。如果您查看代码,它实际上没有做任何其他事情
class EditProfileForm(forms.ModelForm):
member_id = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control', 'placeholder':'Member Id'}))
...
class Meta():
model = User
fields = ('member_id', 'first_name', 'last_name', 'email', 'phone1', 'phone2')
重要的是,您正在显式设置
字段
,因此密码
字段不会出现在表单中。如果您不想使用用户更改表单
的密码行为,那么我将改为子类表单.ModelForm
。如果您查看代码,它实际上没有做任何其他事情
class EditProfileForm(forms.ModelForm):
member_id = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control', 'placeholder':'Member Id'}))
...
class Meta():
model = User
fields = ('member_id', 'first_name', 'last_name', 'email', 'phone1', 'phone2')
重要的是,您正在明确设置
字段
,因此密码
字段不会出现在表单中。感谢您的回复谢谢您的回复