How to use django template tags on returned AJAX calls?

I have a simple AJAX script that takes an input string into a search field with a name AJAXBoxand calls a view function that queries the database with a filter and returns a set of queries for all User objects that match the input parameter. When I go through iteration through a set of queries with django template tags, it doesn't work. I assume this is because the output for my Javascript request does not actually output a set of requests, but some type of string that the django template does not recognize. How can I fix this so that my AJAX calls return true django-compatible requests that perform the normal rendering function in django outputs?

JS for AJAX:

$(document).ready(function(){

$('#AJAXBox').keyup(function()  {

    var searchedterm;
    searchedterm = $(this).val();
    $.get('/AJAXsearch/', {searchterm: searchedterm}, function(data){
        $('#result').html(data);

      });       

    });  
});

For tp; dr for python code essentially:

def AJAXsearch(request):
    searchterm = request.GET['searchterm']
    result = UserObj.objects.filter(person_name=searchterm)
    return HttpResponse(result)

html - :

<div id="result">
    {% for person in result %}
        {{person.property}}
    {%endfor%}
</div>

. , / , .

+4
1

.

:

def AJAXsearch(request):
    searchterm = request.GET['searchterm']
    result = UserObj.objects.filter(person_name=searchterm)
    return render(request,"path/to/your/template.html", {"result":result})

<div>.

, "resultlist.html" , :

resultlist.html:

<div id="result" >
{% for person in result %}
{{person.property}}
{%endfor%} </div>

userprofile.html:

{# Lots of code around the result list #}
{% include "resultlist.html" %}
{# Lots of code around the result list #}
+4

All Articles