[Answered ]-Django render dictionary object in template through ajax get

2👍

✅

You need to return a json object for jQuery to understand.

Try this:

import json
from django.forms.models import model_to_dict

@render_to ('companion/companionSub.html')
def topic(request, id):   

    ids = Catagories.objects.get(catagory=id)

    topics = [model_to_dict(topic) for topic in Topics.objects.filter(fabCatagory_id=ids.id)]
    topic_list = json.dumps({'topics':topics})

    return HttpResponse(topics_list)

Leave a comment