django的Form中添加属性

在ModelForm中添加新的属性

class AuthorForm(ModelForm):
    class Meta:
        model = Author
        widgets = {
            'name': TextInput(attrs={'placeholder': 'name'}),
        }

在Form的成员中添加属性

q = forms.CharField(label='search', 
                    widget=forms.TextInput(attrs={'placeholder': 'Search'}))
原文地址:https://www.cnblogs.com/Mingxx/p/2757992.html