【问题标题】:why i am getting this kind of error Validation Error?为什么我会收到这种错误验证错误?
【发布时间】:2022-01-08 19:33:59
【问题描述】:

错误: 引发异常.ValidationError( django.core.exceptions.ValidationError: ['“” 值的格式无效。它必须是 YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] 格式。']

models.py:

from django.db import models
from django.contrib.auth.models import User
from django.db.models.deletion import CASCADE
from django.utils.timezone import now
class Post(models.Model):
     sno= models.AutoField(primary_key=True)
     title= models.CharField(max_length=255)
     author = models.CharField(max_length=13)  
     slug = models.CharField(max_length=130)  
     content= models.TextField()
     timeStamp = models.DateTimeField(blank=True, null=True )

     def __str__(self):
          return self.title + ' by ' + self.author

class BlogComment(models.Model):
     sno = models.AutoField(primary_key= True)
     comment = models.TextField()
     user = models.ForeignKey(User, on_delete=models.CASCADE)
     parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True)
     timestamp = models.DateTimeField(null=True, blank=True)
    

【问题讨论】:

    标签: python django web


    【解决方案1】:

    在这种情况下,Django 不会将""None 视为相同。因此,您需要验证用户输入以确保处理未设置的日期输入并将其从 "" 更改为 None

    查看 Django 问题跟踪器上的 this issue 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      • 2021-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多