【问题标题】:using ujson instead of django default json serializer使用 ujson 而不是 django 默认的 json 序列化程序
【发布时间】:2015-02-09 22:22:10
【问题描述】:

如您所知,django 使用 json 库将查询集序列化为 json,而 DjangoJSONEncoder 类使用 json.JSONEncoder 作为它的超类,并且 ujson 库中没有这样的类。 如何在 django 序列化程序中使用 ujson 而不是 json?

【问题讨论】:

    标签: json django ujson


    【解决方案1】:

    你可以这样做(使用值):

    some_values = SomeModel.objects.values(
            'pk', 'some_field',
    )
    

    并对其进行序列化:

    mark_safe(ujson.dumps(list(some_values), ensure_ascii=False))
    

    【讨论】:

      猜你喜欢
      • 2016-09-17
      • 1970-01-01
      • 1970-01-01
      • 2019-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多