gpt4 book ai didi

python - drf 中的 UTC 时区验证

转载 作者:行者123 更新时间:2023-12-01 09:27:43 25 4
gpt4 key购买 nike

如何验证/强制用户输入 UTC 时间格式。即用户只能输入以下格式的日期时间

2018-04-16T14:18:15Z

我在序列化器中使用 DateTimeField()。他们的我尝试了这个选项

end_date = serializers.DateTimeField(input_formats=[YYYY-MM-DDThh:mm:ssZ])。

但是我收到序列化器验证错误

"end_date": [ "Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z]." ]

最佳答案

看看here

它说 input_formats 应该是:

A list of strings representing the input formats which may be used to parse the date

尝试传递 input_formats=['YYYY-MM-DDThh:mm:ssZ']['iso-8601']

此外,您可能还想尝试设置格式

关于python - drf 中的 UTC 时区验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50232634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com