How to put object datefield in html input value

Question:

I have a class "client" with an attribute datefield called "birth_date".
I want to give the possibility for update this field.
How can i put the default value in the form, in the input type date? Because the format in "client.birth_date" is different.

{{client.birth_date}} <br>
        </div class="form-group">
            <label for="birth_date">Data di Nascita:</label>
            <input type="date" class="form-control" id="birth_date" name="birth_date" value="{{client.birth_date}}" >
        </div>

enter image description here

If i try with, for example:

 </div class="form-group">
            <label for="birth_date">Data di Nascita:</label>
            <input type="date" class="form-control" id="birth_date" name="birth_date" value="2018-02-01" >
        </div>

The input value is setting true, but the format is different from the one i get

Asked By: FILIPPO REGGIANI

||

Answers:

Try to format the date like so:

<input type="date" name="birth_date" id="birth_date" value="{{ client.birth_date|date:'Y-m-d' }}">

Or set the default date format in settings.py:

DATE_FORMAT = "Y-m-d"
Answered By: lucutzu33