Django如何将Queryset返回给AJAX响应?

时间:2017-02-07 03:22:25

标签: python json ajax django response

拥有QuerySet对象

Input::get('filename')

但有错误

userorder = UserOrder.objects.filter(
        user_id=user_id, is_closed=0)

response_data['uo'] = serializers.serialize('json', [ userorder, ])

[07 / Feb / 2017 05:13:02]" POST / ajax_response / HTTP / 1.1" 500 15833

想让json对象在客户端与他一起工作

1 个答案:

答案 0 :(得分:0)

我认为queryset.values()是您所需要的(note it is already a list):

response_data['uo'] = serializers.serialize('json', userorder.values())