Reputation: 1
I am trying to pass data (step_count_data) from Django to a JavaScript function. Here are the code:
Django
#somecode
step_count_date.append(str(step_count_list[i].startTime.date()))
context = {'step_count_date': json.dumps(step_count_date)}
return render_to_response('patient-profile.html', context, context_instance=RequestContext(request))
Javascript:
step_from_django = JSON.parse({{ step_count_date }})
console.log(step_from_django);
However I got an error: Uncaught SyntaxError: Unexpected token & and the error line is
step_from_django = JSON.parse(["2015-03-19", "2015-04-02"])
What I want is just the date without the " wrap around. Any idea why and how can I fix this? Thanks
Upvotes: 0
Views: 381
Reputation: 2445
You can do it like this:
step_from_django = JSON.parse({{ step_count_date|safe }});
or simply like this:
step_from_django = {{ step_count_date|safe }};
Upvotes: 1