I have a django form that I use in the template with the {{form}} tag, it has a date field, in the form the type of this field appears as “text”, but I want to change the type to “date”, how do I do that?
You’ve got a couple of different options. Which option you choose may depend upon the scope of what you want to do. (It makes a difference whether you want to do this for just one field, for every field in a form, or for every date field in your application.)
The simplest way to do this is in your form definition.
If you’re creating a regular form (not a ModelForm), then you could defined the field something like this:
my_date_field = forms.DateField(widget=forms.DateInput(attrs={'type':'date'}))
If you’re creating a model form, then you would specify this in the widgets
setting of the Meta
class in the ModelForm class. (See Overriding the default fields)
it worked, thank you very much