I receive a dictionary of Django objects in a JSON format via AJAX in the template. Is there any possibility to render this dictionary through a Django template-tag? Can I call a Django template-tag from jQuery and transfer the object as a parameter to it?
The current solution is to tediously construct the html in jQuery:
$.ajax({
url: url,
type: "POST",
success: function(data) {
var obj = $.parseJSON(data);
$.each(obj, function() {
data = this['fields'];
post += "<p id='" + this['pk'] + "'>" + data['creator'] + data['created'] + data['body'];
post += "depth: " + data['depth'];
post += "<a name='" + this['pk'] + "' class='show_answers' href='" + show_url + "'>Show</a>";
post += "<a name='" + this['pk'] + "' href='" + answer_url + "'>Answer</a></p>";
post += "<div id='" + this['pk'] + "_div'></div>";
});
$('#' + div_id).html(post);
},
crossDomain: false
});