python 密码字段无法呈现

lb3vh1jj  于 2023-01-12  发布在  Python
关注(0)|答案(2)|浏览(124)

未呈现密码字段

我的forms.py看起来像这样:

from django import forms

class RegisterForm(forms.Form):
  username =forms.CharField()
  password =forms.PasswordInput()
  email =forms.EmailField(label='E-Mail')
  gender =forms.ChoicField(choices=[('Male', 'male'), ('Female', 'female')])

当我运行它时,除了密码字段外,其他字段都会显示。

zi8p0yeb

zi8p0yeb1#

PasswordInput方法不是字段。它是用于格式化字符字段的小部件。请尝试:

password = forms.CharField(max_length=32, widget=forms.PasswordInput)
zfciruhq

zfciruhq2#

你可以用,也许会有帮助。

password = forms.CharField(widget=forms.PasswordInput)

相关问题