【发布时间】:2019-12-15 08:21:54
【问题描述】:
我想将一些 Html attr 传递给由crispy 生成的表单字段
我在 django 2.2.3 中尝试使用此代码
class AddForm(forms.Form):
todo = forms.CharField(max_length=128, attrs={'placeholder':'What do you want to do?'})
但我遇到了一个错误
from .forms import AddForm
File "C:\Users\HP\django_project\todo\forms.py", line 4, in <module>
class AddForm(forms.Form):
File "C:\Users\HP\django_project\todo\forms.py", line 5, in AddForm
todo = forms.CharField(max_length=128, attrs={'placeholder':'What do you want to do?'})
File "C:\Users\HP\AppData\Local\Programs\Python\Python37\lib\site-packages\django\forms\fields.py", line 214, in __init__
super().__init__(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'attrs'
【问题讨论】:
-
使用 widget=forms.TextInput(attrs={'placeholder': '你想做什么?'})
标签: python django django-forms django-crispy-forms