Hello! There is a form on search (I use without ajax
). The result is normal. I decided to use ajax
and json
. Question: how to return the data in json
format, the documentation is a bit confused ...
As now I send:
def dictfetchall(cursor): desc = cursor.description return [dict(zip([col[0] for col in desc], row))for row in cursor.fetchall()] if request.GET['searchType'] == 'FIO': cursor = connection.cursor() cursor.execute('SET NAMES utf8;') cursor.execute(sql2.format(request.GET.get('search','').encode("utf-8"))) return render(request, 'search/search.html', {'forms': SearchForm(), 'res': dictfetchall(cursor)})