Thursday, July 31, 2014

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

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?

>
> On Wednesday, July 30, 2014 7:44:48 PM UTC-6, Camilo Torres wrote:
>
> Hello, you can use 'verbatim':
> https://docs.djangoproject.com/en/1.6/ref/templates/builtins/#verbatim
> <https://docs.djangoproject.com/en/1.6/ref/templates/builtins/#verbatim>
>
> On Wednesday, July 30, 2014 6:59:05 PM UTC-4:30, G Z wrote:
>
> 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 }
>
> --
> 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+unsubscribe@googlegroups.com
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto:django-users@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.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/53DAC7E4.1000101%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment