I am using a calendar widget using django forms, part of the code-
class DateForm(forms.ModelForm):
helper.layout = Layout(
Div(
Field('start', placeholder='date')
)
class Meta:
model = Date
widgets = {
'start': forms.DateInput(attrs={'class':'datepicker'}),
}
How can I add a default value of todays date to the 'start' variable? I cannot seem to find any default for dateinput. Very new to Django and javascript- thanks for the help!!
Change :
'start': forms.DateInput(attrs={'class':'datepicker'})
to
'start': forms.DateInput(attrs={'class':'datepicker', 'value': datetime.now().strftime("%d-%m-%Y")})
This will set a default value for the date input field. You can change the date format as per the format you want to set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With