is not JSON serializable

前端 未结 2 1150
醉梦人生
醉梦人生 2020-12-03 02:27

I have the following ListView

import json
class CountryListView(ListView):
     model = Country

    def render_to_response(self, context, **response_kwargs)         


        
2条回答
  •  清歌不尽
    2020-12-03 02:49

    class CountryListView(ListView):
         model = Country
    
        def render_to_response(self, context, **response_kwargs):
    
             return HttpResponse(json.dumps(list(self.get_queryset().values_list('code', flat=True))),mimetype="application/json") 
    

    fixed the problem

    also mimetype is important.

提交回复
热议问题