How to Use an HTML5 Date Input With Django Forms

preview_player
Показать описание
The default date input in Django is just a plain text input, so in this video I show you how to use the HTML5 date widget in a Django form.

Рекомендации по теме
Комментарии
Автор

tired of dealing with javascript libraries with no result, I found your video. thanks man you are really something!

marcelollosa
Автор

this is from 4 years but GOLD.... thank you so much it helps a lot

zcsmlyh
Автор

Really helpful, I tried to find out how to do this for long time and only found complex solutions, really simple. Thanks.

jairoandressarmientogarzon
Автор

Congrats man! this video is really good and pragmatic. Short, straight useful with great value. No fancy libraries. continue making videos like this.

canislatrans
Автор

Thank you. I have been struggling on this datepicker for so long and not a single post on whole web had this solution. I use forms.ModelForm for my forms. Now I integrated your technique and created DateInput() class as you shown in your video. It worked and now i have datepicker at the right corner on my payment_date field.

class DateInput(forms.DateInput):
input_type = 'date'

class
class Meta:
model = StudentFee
fields = '__all__'
widgets = {'payment_date': DateInput()}

coolguycoolguy
Автор

I have been looking for this for the past 2 days, tyvm

spreadhysteria
Автор

How do you format it to (day/month/year) or (year/month/day)?

PhiVaGoo
Автор

Thank you so much. You are one of the best teachers - simple right to the point. No BS. I spent so much time looking at django datepick etc. - all those BS doing all the unnecessary complicate code.

timsitestats
Автор

Thank you, like others, I spent a long time searching. 2 lines for a class def and it works with forms.ModelForm too. So grateful.

glyndavies
Автор

Thank you so much for this very concise and to the point video. Solves a big problem with just a few lines of code.👍

yoip
Автор

Thank you so much, I searched for this in my whole life, finally found

vishushetty
Автор

Where have you been all my life :-). I've been wrestling around with bootstrap 4 datepicker for 2 days now and couldn't get it to work. Every example I found had different installs, includes, loads, and code. Just three lines of code and your solution worked perfectly. I've ripped out every occurrence of anything to do with bootstrap4 datepicker. Thanks much!

howardfreedman
Автор

Thank you! Such a succinct video and perfectly describes how to implement this! I searched for too long before I found this.

nlenn
Автор

I searched a lot and here you got it.... Thanks a man :)

bhupenderlawa
Автор

Also works with ModelForm:

### forms.py
from django import forms
from django.forms import ModelForm

class
input_type = 'month'

class ContratoForm(ModelForm):
class Meta:
model = Contrato
fields = ['cliente', 'nombre', ]
widgets = {'primer_abono': InputMensual(), }

matiasgatti
Автор

The cleanest tutorial on YouTube about widgets! Thx from Ukraine bro!

richardclark
Автор

Thank you so much, you solved in 3 minutes what hours of other videos and googling couldn't. Btw, do you have any video expanding on this where you implement a button that empties the date field?

Gamarus
Автор

OMG. All-Star video! My head hurt looking at all the js solutions while this is so simple.

shmish
Автор

Dude thank you so much!!! I spent so long trying to figure out the date input problem and this video helped so much!

lakshmakhija
Автор

by far this is the easiest solution I've found to this problem

m.ahmadsulehari