I have a DateTimeField :
start_time=forms.DateTimeField(input_formats='%y-%m-%d %H:%M')
and in html
{{form.start_time}}
but no matter what i entre in th field, like: 2013-07-07 19:00 it will always give me an error : enter valid date/time, what is worng here? Thanks in Advance
DateTimeField in Django Forms is a date field, for taking input of date and time from user. The default widget for this input is DateTimeInput. It Normalizes to: A Python datetime. datetime object.
DateTimeField is a date and time field which stores date, represented in Python by a datetime. datetime instance. As the name suggests, this field is used to store an object of datetime created in python. The default form widget for this field is a TextInput .
DATETIME_FORMAT="%Y-%m-%d%H:%M:%S"
If yes try to disable this behavior, set the novalidate attribute on the form tag As <form action="{% url 'new_page' %}", method="POST" novalidate> in your html file.
Write the definition like this:
start_time=forms.DateTimeField(input_formats=['%Y-%m-%d %H:%M'])
Note that input_formats is a list and the Y is upper case. That should work.
Just did some trial and error. When specifying input_formats
you have to consider that for a widget format='whatevers in here'
is a string whereas input_formats=['whatevers in here', 'whatever else']
is a list.
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