Flask 棉花糖模式中的日期时间格式

Shi*_*ose 2 python datetime datetime-format flask-sqlalchemy marshmallow

我想使用烧瓶棉花糖中的架构为从模型检索的数据应用自定义日期时间格式。

目前使用的架构如下:

class ScheduleListSchema(ma.Schema):
    class Meta:
        fields = ('id', 'start_time', 'end_time')
Run Code Online (Sandbox Code Playgroud)

在此start_time格式中2018-12-05T03:00:00+00:00

所以我想为架构中的值创建自定义格式start_time

Shi*_*ose 6

您可以使用这样的代码:

start_time = fields.fields.DateTime(format='%Y-%m-%dT%H:%M:%S%z')