[Django]-How to use TimeInput widget in Django forms?

9👍

By default the TimeInput widget renders as an html input field of type text:

<input type="text" name="time" id="id_time">

If, instead, you want to render it as an html input field of type time:

<input type="time" name="time" id="id_time">

then in the meta widgets section of your ModelForm class add a type attribute like this:

'time': forms.TimeInput(attrs={'type': 'time'})

👤User

0👍

I had the same problem with TimeInput().
I ended up following Vitor Freitas’ tutorial and using Django Tempus Dominus, which includes a Time Picker option.

Hope this helps!

Leave a comment