[英]Passing DateTime data from Django to Javascript
I am trying to pass data (step_count_data) from Django to a JavaScript function. 我正在尝试将数据(step_count_data)从Django传递到JavaScript函数。 Here are the code:
这是代码:
Django 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: 使用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 但是我收到一个错误:Uncaught SyntaxError:意外的令牌&和错误行是
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 我想要的只是没有日期的日期。任何想法为什么以及如何解决这个问题?谢谢
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 }};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.