How do I get Django to ignore javascript code because its throwing an exception

105 views
Skip to first unread message

G Z

unread,
Jul 30, 2014, 7:29:05 PM7/30/14
to django...@googlegroups.com
so im using the following java script

var cpuChart = document.getElementById('cpu').getContext('2d');
        new Chart(cpuChart).Line(cpuData,{
        bezierCurve: false,
        datasetFill : false,
        legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].lineColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
        
        });

django will see the % signs and think it is block content as it says below i copy and pasted the error, how i get django to ignore a section of my code and not parse the tags for that section.


Request Method:POST
Request URL:http://127.0.0.1:8000/vmstats/
Django Version:1.6.5
Exception Type:TemplateSyntaxError
Exception Value:
Invalid block tag: '><li><span'
Exception Location:/usr/local/lib/python2.7/dist-packages/django/template/base.py in invalid_block_tag, line 332
Python Executable:/usr/bin/python
Python Version:2.7.5
Python Path:
['/home/grant/workspace/Django Projects/trunk/holon',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
 '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']
Server time:Wed, 30 Jul 2014 23:27:32 +0000

Error during template rendering

In template /home/grant/workspace/Django Projects/trunk/holon/portal/templates/vmstats.html, error at line 162

Invalid block tag: '><li><span'

152 var iopsChart = document.getElementById('iops').getContext('2d');
153 new Chart(iopsChart).Line(iopsData,{
154 bezierCurve: false,
155 datasetFill : false,
156 });
157
158 var cpuChart = document.getElementById('cpu').getContext('2d');
159 new Chart(cpuChart).Line(cpuData,{
160 bezierCurve: false,
161 datasetFill : false,
162 legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].lineColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
163
164 });
165 }

Camilo Torres

unread,
Jul 30, 2014, 9:44:48 PM7/30/14
to django...@googlegroups.com

G Z

unread,
Jul 31, 2014, 1:37:45 PM7/31/14
to django...@googlegroups.com
doesn't work because then my charts dont appear when i enclose the script tag.

Mike Dewhirst

unread,
Jul 31, 2014, 6:49:37 PM7/31/14
to django...@googlegroups.com
On 1/08/2014 3:37 AM, G Z wrote:
> doesn't work because then my charts dont appear when i enclose the
> script tag.

Can you put the js into a file and use the template to include it?
> line *162*
>
>
> Invalid block tag: '><li><span'
>
> 152 var iopsChart =
> document.getElementById('iops').getContext('2d');
> 153 new Chart(iopsChart).Line(iopsData,{
> 154 bezierCurve: false,
> 155 datasetFill : false,
> 156 });
> 157
> 158 var cpuChart = document.getElementById('cpu').getContext('2d');
> 159 new Chart(cpuChart).Line(cpuData,{
> 160 bezierCurve: false,
> 161 datasetFill : false,
> 162 legendTemplate : "<ul
> class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0;
> i<datasets.length; i++){%><li><span
> style=\"background-color:<%=datasets[i].lineColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
>
> 163
> 164 });
> 165 }
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b5db3b20-bceb-4b72-bc83-d52adb948b8c%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/b5db3b20-bceb-4b72-bc83-d52adb948b8c%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages