I want to hand over a stringarray from my views.py to the template and use this strings for D3.
views.py:
def index(request):
template = loader.get_template("myApp/index.html")
data = ["a","b","c"]
context = RequestContext(request,{"data":data})
return HttpResponse(template.render(context))
index.html:
<html>
<head>
<title>Some project</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
</head>
<body>
<h1>Some project visualisation</h1>
<script type="text/javascript">
var dataArray = {{ data }};
...
At "var dataArray = {{ data }};" I get a syntax error.
I looked this up in the browser-console and my dataArray
seems to look like this:
var dataArray = ['a','b','c']
I have also tried to use json.dumps(data), but I get a similar dataArray like:
var dataArray = ["a","b","c"]