这是我的密码
class LoginForm(AuthenticationForm):
username = UsernameField(label='username', widget=forms.TextInput(attrs={'autofocus':True,'class':'form-control'}))
password = forms.CharField(label =_("Password"), strip=False, widget=forms.PasswordInput(attrs={'autocomplete':'current-password', 'class':'form-control'}))
当我运行服务器时,发生此错误(NameError:未定义名称“UsernameField”)
class LoginForm(AuthenticationForm):
File "E:\07_Django_All\03_ecommerce_site(Project)\Ecommerce_site\app\forms.py", line 19, in LoginForm
username = UsernameField(label='username', widget=forms.TextInput(attrs={'autofocus':True,'class':'form-control'}))
NameError: name 'UsernameField' is not defined
2条答案
按热度按时间bfnvny8b1#
必须从
django.contrib.auth.forms
导入UsernameField
b4lqfgs42#
1.必须从
django.contrib.auth.forms
导入UsernameField
1.必须从
django.utils.translation
导入gettext
和gettext_lazy as _