django:value具有无效的日期格式。它必须是YYYY-MM-DD格式 [英] django: value has an invalid date format. It must be in YYYY-MM-DD format

查看:7049
本文介绍了django:value具有无效的日期格式。它必须是YYYY-MM-DD格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题

我使用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>

您将解决两个问题:


  1. 当钥匙不存在,这将默认为,这是您的模型的有效输入,因为您有 null = True


  2. 如果密钥存在但其空白'',则会导致这是您的模型的有效值。



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:

  1. When the key does not exist, this will default to None, which is valid input for your model as you have null=True.

  2. If the key exists but its blank '', then it will result in None which is a valid value for your model.

这篇关于django:value具有无效的日期格式。它必须是YYYY-MM-DD格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆