Reputation: 411
I'm new to Django and try to understand how to return 2 different kind of response type inside one return Jsonresponse :
view.py
def article_filter_mobile(request):
# Here I'm trying to get the total records number of my DB
number_of_rec = Record.objects.count()
# Need to access {{number_of_rec}} in test.html
count = render(request, 'test.html', {'number_of_rec': number_of_rec})
# here I'm listing all datas of my DB
data = dict()
locations = Record.objects.raw("SELECT * FROM myDb")
available_lessons = [model_to_dict(l) for l in locations]
# Need to access {{available_lessons|safe}} in a JS script inside grid_mobile.html
data['html_table'] = render_to_string('grid_mobile.html',
{'available_lessons': available_lessons},request=request)
# I think my problem is here as data and count are not in the same format
return JsonResponse(data,count)
Can someone help me to understand what is wrong in this code ? Thanks
Upvotes: 0
Views: 89