HenryM HenryM -4 years ago 110
HTML Question

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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download