标签:turn code import encode efault lse elf style class
import json from datetime import date from datetime import datetime class JsonCustomEncoder(json.JSONEncoder): def default(self, field): if isinstance(field, datetime): return o.strftime(‘%Y-%m-%d %H:%M:%S‘) elif isinstance(field, date): return o.strftime(‘%Y-%m-%d‘) else: return json.JSONEncoder.default(self, field)
由于json.dumps时无法处理datetime日期,所以可以通过自定义处理器来做扩展,如:
标签:turn code import encode efault lse elf style class
原文地址:https://www.cnblogs.com/bozhengheng/p/12081698.html