I am trying to send mysql query results in the context of my Django template to a Javascript variable. I am using pivot.js https://github.com/nicolaskruchten/pivottable which requires jquery and the jquery UI.
In the Django view:
cursor.execute(query)
data = dictfetchall(cursor)
json_data = json.dumps(data, cls=DateTimeEncoder)
context['pivot_data'] = json_data
This works and I am able to see the data in the javascript console but for some reason it is not formatted properly.
From my Django template:
{% load staticfiles %}
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<script type='text/javascript' src="{% static "js/pivot.js" %}"></script>
<script type='text/javascript'>
var pivotData = '{{ pivot_data }}';
$("#output").pivotUI(
pivotData,
{
rows: ["XXX"],
cols: ["YYY"]
}
);
</script>