1👍
✅
If you want to format the data first, then send a rendered template fragment as your Ajax response, rather than JSON.
- [Answered ]-Django : value too long for type character varying(30) when input not even 10 characters
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.
- [Answered ]-Django use UTC offsets for current timezone
- [Answered ]-How can I access the elements of a foreign set for a model in Django's get_context_data method?
- [Answered ]-Django url r'^page/ should redirect to the same dynamic template whatever argument behind
- [Answered ]-Showing a related fields attribute
Source:stackexchange.com