S
S
Sergey08082017-10-12 14:51:02
Django
Sergey0808, 2017-10-12 14:51:02

Python Django, why not serialize python dictionary to object JSON?

There is such a view:

def lazy_ajax(request):
        if request.is_ajax():
           news = {}
           query = request.GET.get('value', 14)
           news['news'] = News.objects.all()[query:]
           return JsonResponse(json.dumps(news, ensure_ascii=False), content_type='application/json', safe=False)

I am getting this error:
TypeError: <QuerySet [<News: В Челябинске эксперты обсудят  и т.д.

How can I do the conversion of a dictionary?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question