Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django:值的日期格式无效。它必须是YYYY-MM-DD格式_Python_Django_Date - Fatal编程技术网

Python django:值的日期格式无效。它必须是YYYY-MM-DD格式

Python django:值的日期格式无效。它必须是YYYY-MM-DD格式,python,django,date,Python,Django,Date,我有个问题 我使用xpath从网站获取项目['releaseday']。 当xpath没有得到值时 它将导致错误: django.core.exceptions.ValidationError: [u"'' value has an invalid date format. It must be in YYYY-MM-DD format."] 在my models.py中,我设置null=True,blank=True似乎不起作用 releaseday = models.DateFi

我有个问题
我使用xpath从网站获取
项目['releaseday']

当xpath没有得到值时

它将导致错误:

django.core.exceptions.ValidationError: [u"'' value has an invalid date format. It must be in YYYY-MM-DD format."]
在my models.py中,我设置null=True,blank=True似乎不起作用

releaseday      = models.DateField(null=True,blank=True)    
    if 'releaseday' not in item:
        item['releaseday']=''   
我尝试添加此代码,但不起作用

releaseday      = models.DateField(null=True,blank=True)    
    if 'releaseday' not in item:
        item['releaseday']=''   
如何编辑???
请指导我,谢谢你

使用
物品。获取('releaseday')或无

您将解决两个问题:

  • 当密钥不存在时,这将默认为
    None
    ,这对于您的模型是有效的输入,因为您有
    null=True

  • 如果密钥存在,但其为空
    '
    ,则它将导致
    None
    ,这是您的模型的有效值