javascript - Django template parses string as integer -


i have list looks following:

[(2,'09-07-2014')] 

when access list @ client side can access using:

{% item in list %} console.log( {{ item.0 }} + ' , ' + {{ item.1 }} ) {% endfor %} 

problem item.0 returns 2 should item.1 returns -2012 9-7-2014 in integer representation compute -2012.

how make client side script realize string not integer.

below whole listing of code:

chartdata= getchartdata(request.session['userphone']) log.debug(chartdata) return render(request,'users.html',{'table':table,'topics':request.session['topics'],'profilepic':request.session['profilepic'],'chartdata':chartdata,'time':str(time.time())}) 

the log.debug(chartdata) returns following in log file:

[11/jul/2013 18:02:15] debug [karnadash.views:179] [(85, '2013-07-08'), (120, '2013-07-08'), (205, '2013-07-08'), (305, '2013-07-08'), (405, '2013-07-08'), (505, '2013-07-08'), (547, '2013-07-09'), (564, '2013-07-09'), (581, '2013-07-09'), (607, '2013-07-09'), (624, '2013-07-09'), (659, '2013-07-09'), (694, '2013-07-09'), (711, '2013-07-09'), (737, '2013-07-09'), (754, '2013-07-09'), (771, '2013-07-09'), (871, '2013-07-09')] 

django not doing this, javascript is, because have not told js dealing string. if @ html source, see happening - this:

console.log( 2 + ' , ' + 09-07-2014 ) 

there aren't quotes around date value, because haven't put there, js thinks it's expression. it's solved:

console.log( '{{ item.0 }}' + ' , ' + '{{ item.1 }}' ) 

or, better, since js doesn't care fact they're separate items in django:

console.log( '{{ item.0 }} , {{ item.1 }}' ) 

Comments