I really hope someone will help with the problem I've been stuck. I have a below code in my index.html:
$(document).ready(function() {
$('#mydata').DataTable( {
"ajax": {
"url": '{% static "myapp/supplier.json" %}', //<= works
{# "url": '{{ suppliers_all }}',#} //<=does not work
"dataSrc": ""
},
"columns": [
{ "data": "name" },
{ "data": "classification" },
]
} );
} );
If I have source to "supplier.json" file it works like a charm, but if I try to pass django variable which gives exactly same out, it does not work.
Here's the "views.py":
def index(request):
suppliers_all = Supplier.objects.all().values('name', 'classification')
suppliers_all = json.dumps(list(suppliers_all))
context = {'suppliers_all': suppliers_all,
}
return render(request, 'myapp/index.html', context)
Here is JSON output"
[{"classification": "Base Supplier", "name": "Supplier Name1"}, {"classification": "Strategic Supplier", "name": "Supplier Name2"}]
Any ideas?
thanks