0

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

1 Answer 1

1

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 }};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.