1. add attrs in widget
number = forms.CharField(widget=forms.TextInput(attrs={'autocomplete': 'off', 'type': 'number'}))
2. use __init__
class YourModelForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(YourModelForm, self).__init__(*args, **kwargs)
self.fields['number'].widget.attrs.update({
'autocomplete': 'off',
'type': 'number',
})
3. use Meta
class YourModelForm(ModelForm):
class Meta:
model = YourModel
fields = ('number', 'title', 'birth_date')
widgets = {
'number': Textarea(attrs={'autocomplete': 'off', 'type': 'number'}),
}
4. django-widget-tweaks
{% load widget_tweaks %}
...
<div class="field">
{{ form.number|attr:"autocomplete:off"|add_class:"my_css_class" }}
</div>
'backend > django' 카테고리의 다른 글
Django: Filter with CharField length (0) | 2018.07.26 |
---|---|
Django: show invalid message in django loginform (0) | 2018.07.23 |
Django: channels 2.0 with nginx + daphne (0) | 2018.06.20 |
Django: use ckeditor in django - django ckeditor (0) | 2018.05.24 |
Django: logout when get for django-allauth (0) | 2018.05.23 |