Enter valid date error

30 views
Skip to first unread message

ANi

unread,
Aug 6, 2019, 2:28:24 AM8/6/19
to Django users
I've change the default date field widget slightly,
but only like this and also define the DATE_INPUT_FORMATS



class DateInput(DateTimeBaseInput):
input_type = 'date'
format_key = 'DATE_INPUT_FORMATS'


DATE_INPUT_FORMATS = [
'%Y-%m-%d',
]


but still get error on the date field, only success at the first time after I restart the server

any reason could be?

DPM

unread,
Aug 6, 2019, 12:54:37 PM8/6/19
to django...@googlegroups.com
Hey Ani,

Change format_key = DATE_INPUT_FORMATS.
Omit the quotes. Then will work fine. 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6d5257f5-e7aa-41ff-a0f7-8d4936e73167%40googlegroups.com.

sachinbg sachin

unread,
Aug 6, 2019, 2:54:41 PM8/6/19
to django...@googlegroups.com
Give the format in year month date it will be resolved then

ANi

unread,
Aug 7, 2019, 10:14:34 PM8/7/19
to Django users
Thanks for your help!

Sipum,
I have tried many possibilities and it is some how fixed and I actually don't know why, like why it is broken.........
but if you look into the class DateInput provided by Django:


class DateInput(DateTimeBaseInput):
format_key = 'DATE_INPUT_FORMATS'
template_name = 'django/forms/widgets/date.html'


it does the same thing, and the template only includes the template same as DateTimeBaseInput(which I don't get it)

so I end up inheriting the Django DateInput to create my own DateInput, all I need is change the input_type

from django.forms.widgets import DateInput as djangoDateInput


class DateInput(djangoDateInput):
input_type = 'date'

  
or consider what sachin said, simply set format_key = '%Y-%m-%d'





ANi於 2019年8月6日星期二 UTC+8下午2時28分24秒寫道:
Reply all
Reply to author
Forward
0 new messages