Answer the question
In order to leave comments, you need to log in
How to work with dates on a form in Django?
I can not figure out how to accept the DateTime on the form.
I get an error
Please enter a valid date and time.
Enter a valid date/time.
On the form I use the DateInput widget with type datetime-local and localize=True
forms.py
date_field = forms.DateTimeField(required=False, widget=DateInput(attrs={'type': 'datetime-local'}),
initial=datetime.date.today(), localize=True)
<input type="datetime-local" value="2017-11-10T00:00">
LANGUAGE_CODE = 'ru-ru'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = True
USE_L10N = True
USE_TZ = True
Answer the question
In order to leave comments, you need to log in
The format is invalid. If only I looked in the dock https://docs.python.org/3/library/datetime.html#st...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question