如何使用django-filters为使用过滤器的自定义css类属性添加占位符。
filter.py
class PlaceFilter(django_filters.FilterSet):
name = django_filters.CharFilter(lookup_expr='icontains')
class Meta:
model = Places
fields = ['name']
html
<form method="GET">
{{ filter.form.name }}
<label for="name"></label>
</form>
答案 0 :(得分:1)
我找到了解决方案
class PlaceFilter(django_filters.FilterSet):
name = django_filters.CharFilter(lookup_expr='icontains', widget=forms.TextInput(attrs={
'placeholder': 'Search place', 'class': 'input__search'}))
class Meta:
model = Places
fields = ['name']