1、问题
默认情况下,如果是密码字段,会自动清空输入内容
2、解决办法
在form的class中,增加属性 render_value=True :
password = forms.CharField(widget=forms.PasswordInput(render_value=True,))
另一个例子:
password = forms.CharField(label='密码', max_length=100,
widget=forms.PasswordInput(render_value=True, attrs={'placeholder': '密码(最短6位)'}))
另一个例子:
prmqpass = forms.CharField(widget=forms.PasswordInput(render_value=True))
3、参考文章
- https://stackoverflow.com/questions/16664914/password-field-data-gets-clear-after-submitting
- https://blog.csdn.net/u011519550/article/details/113764309
- https://docs.djangoproject.com/en/4.1/ref/forms/widgets/#passwordinput
- https://stackoverflow.com/questions/33835882/django-form-validation-dont-keep-password-with-validationerror/33839975#33839975