您必须使用占位符属性
class LoginForm(forms.Form): username = forms.CharField(label='username') password = forms.CharField(label='password') def __init__(self, *args, **kwargs): super(LoginForm, self).__init__(*args, **kwargs) self.fields['username'].widget.attrs['placeholder'] = 'username' self.fields['password '].widget.attrs['placeholder'] = 'password'
要么
class LoginForm(forms.Form): username = forms.CharField(label='username',widget=forms.TextInput(attrs={'placeholder':'username'})) password = forms.CharField(label='password',widget=forms.PasswordInput(attrs={'placeholder':'password'}))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)