“Enter a valid date” Error in Django Forms DateField

百般思念 提交于 2019-12-25 09:43:05

问题


I know there are a lot of threads alredy talking about this but there is none that remotely solved my problem. This is really weird because everything has been done how it's meant to be done.

Here is my forms.py:

from django import forms
from airspress import settings

class searchForm(forms.Form):
depDate1 = forms.DateField(required=False,  input_formats=settings.DATE_INPUT_FORMATS)
depDate2 = forms.DateField(required=False, input_formats=settings.DATE_INPUT_FORMATS)
cityDep = forms.CharField(required=False)
cityArr = forms.CharField(required=False)

And here is a simple test :

data = {'depDate1':'1-5-2015'}
boo = searchForm(data)
if boo.is_valid():
   pass
print boo.errors
#print: <ul class='errorlist'><li>depDate1<ul><li>Enter a valid date</li></ul></li></ul>

In short i have an "Enter a valid date" error, And i've tried absolutely everything, every kind of date format i can think of, it only works when i create an actual datetime.datetime object and assign to the field value. I've done lot of testing in actual rendered html form to no avail.

Hope I'm actually missing something and i'm not just doomed for the day...

Thank you very much !


回答1:


Well, i don't know what to say... Maybe Django had a "caching" problem or something like that. Because there don't seem to be a scripting problem which just happen to solve itself (unless there's a 3035 year robot software around). If anyone has this problem, follow the answers on other questions here, like this one :

django Enter a valid date. validation error

Thank you very much for you time @AirThomas .



来源:https://stackoverflow.com/questions/27830901/enter-a-valid-date-error-in-django-forms-datefield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!