0👍
✅
You assign the form field forms.IntegerField to "widget" which is wrong:
class ContactForm(forms.Form):
# ... # Wrong
phone = forms.CharField(widget=forms.IntegerField)
# ...
So, instead, you need to assign the widget forms.NumberInput to "widget" which is correct:
class ContactForm(forms.Form):
# ... # Correct
phone = forms.CharField(widget=forms.NumberInput)
# ...
6👍
forms.IntegerField
is not a widget but a field type on form.
What you need is a forms.NumberInput
phone = forms.CharField(widget=forms.NumberInput)
👤AKS
1👍
You can use
phone = forms.CharField(widget=forms.TextInput(
attrs={
'type' : 'number',
'class' : 'your_class'
}))
- [Django]-Django rest framework Serializer validate field data type
- [Django]-How to serialize recursive relationship with self in Django REST Framework?
Source:stackexchange.com