[Answered ]-Using django serializer to json while AJAX but using templatetags on response

1👍

If you want to format the data first, then send a rendered template fragment as your Ajax response, rather than JSON.

1👍

On the client side you can use some javascript based template engine like mustache.

/* For example */
var json_data = {
    name: "Joe",
    amount: 10.55
};

var template = "{{name}} spends {{amount}}";
$('#some-div').html(Mustache.render(template, json_data));

On django templates it is a pain to escape {{ stuff }} without something like the very handy {% verbatim %} template tag provided by this gist.

Another approach is: use static files as client side templates and fetch them with AJAX calls.

Leave a comment