Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python/Django date field in html input tag

I'm trying to display a date in an input field as so:

<tr><td>Date of Birth</td><td><input type="date" name="DOB" value="{{m.dob|date:"d/m/Y"}}" required=True></td></tr>

where m.dob is defined in the model as:

dob = models.DateField('Date of Birth', blank=True, null=True)

The HTML input tag shows the date as dd/mm/yyyy when the page is loaded but I can see the field has taken the value assigned. How do I get it to display correctly?

Thanks for help

like image 919
HenryM Avatar asked Dec 04 '25 21:12

HenryM


1 Answers

The problem is value="{{m.dob|date:'d/m/Y'}}" which must be specified as value="{{m.dob|date:'Y-m-d'}}"

like image 103
HenryM Avatar answered Dec 06 '25 09:12

HenryM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!