To ensure your Python object can be understood by Javascript, it needs to be converted into a format such as JSON. This can be accomplished using the simplejson
library in your view:
from django.utils import simplejson
from django.shortcuts import render
def some_view(request):
...
python_data = [
{ 'name' : 'Alice', 'age' : 25 },
...
]
json_data = simplejson.dumps(python_data)
render(request, "some_template.html", { 'data' : json_data })
In your template, include the following script:
<script>
var data = {{ data|safe }}
</script>
(While Simplejson is suitable for converting regular Python objects, Django's serializers should be used if you need to convert a QuerySet)