问题描述
DRF: 2018-12-21T19:17:59.353368Z Model field: 2018-12-21T19:17:59.353368+00:00
我想得到的效果
"buy_time": "2022-12-27 22:48:48"
解决方案
一、全局方案 在settings.py里 设置:
REST_FRAMEWORK = { 'DATETIME_FORMAT': "%Y-%m-%d %H:%M:%S",}
二、局部处理 在序列化器里处理
class OrderSerializer(serializers.ModelSerializer): buy_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S") class Meta: model = Order fields = ("customer_name", "product_name", "quantity", "amount", "buy_time")
参考资料:https://qa.1r1g.com/sf/ask/3772284351/
标签:-%,方案,00,buy,格式化,rdf,time,serializers,12 From: https://www.cnblogs.com/python100/p/17011550.html