Saturday, December 29, 2012

problem while passing a list of string to javascript in template

Hello Everyone,
I have problem while passing a list of string from django views to javascript template. The quotation mark gets converted into hex and I cannot use it to plot graph using jpplot. I even tried replace method of javascript to replace the hex to convert to '. 

The codes are as follows:
From :
from django.shortcuts import render_to_response

def abc(request):
s1=[1, 5 , 8 , 3]
ticks=["a", "b", "c", "d"]
return render_to_response('abc.html', {'s1':s1, 'ticks':ticks})

From .html file (of template):
 <script class="code" type="text/javascript">$(document).ready(function(){
        $.jqplot.config.enablePlugins = true;
var s1 ={{ s1 }}
var ticks ={{ ticks }}
        plot1 = $.jqplot('chart1', [s1], {
            // Only animate if we're not using excanvas (not in IE 7 or IE 8)..
            animate: !$.jqplot.use_excanvas,
                pointLabels: { show: true }
            axes: {
                xaxis: {
                    renderer: $.jqplot.CategoryAxisRenderer,
                    ticks: ticks
            highlighter: { show: false }
            function (ev, seriesIndex, pointIndex, data) {
                $('#info1').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);

when I view the source of the html file i get {{ ticks }} as
[&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;]

You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment