django:value具有无效的日期格式。它必须是YYYY-MM-DD格式 [英] django: value has an invalid date format. It must be in YYYY-MM-DD format
问题描述
我使用xpath从网站获取
item ['releaseday']
。当xpath没有获得价值
它会导致错误:
django .core.exceptions.ValidationError:[u值的日期格式无效,它必须是YYYY-MM-DD格式。]
在我的models.py我设置null = True和blank = True似乎不工作
releaseday = models.DateField(null = True,blank = True)
代码,但不工作
如果'releaseay'不在项目中:
item ['releaseday'] =''
如何编辑???
请指导我谢谢
使用 item.get('releaseday')或无
p>
您将解决两个问题:
-
当钥匙不存在,这将默认为
无
,这是您的模型的有效输入,因为您有null = True
。 -
如果密钥存在但其空白
''
,则会导致无
这是您的模型的有效值。
I have a question
I use xpath to get item['releaseday']
from website.
When xpath didn't get value
It will cause error :
django.core.exceptions.ValidationError: [u"'' value has an invalid date format. It must be in YYYY-MM-DD format."]
in my models.py I set null=True and blank=True seems like not work
releaseday = models.DateField(null=True,blank=True)
I try add this code,but not work
if 'releaseday' not in item:
item['releaseday']=''
How can I edit???
Please guide me thank you
Use item.get('releaseday') or None
.
You'll solve two problems:
When the key does not exist, this will default to
None
, which is valid input for your model as you havenull=True
.If the key exists but its blank
''
, then it will result inNone
which is a valid value for your model.
这篇关于django:value具有无效的日期格式。它必须是YYYY-MM-DD格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!