admin管理员组

文章数量:1317898

I am using jinja2 templating language in my GAE-python project. I have tried to use the jquery-upload for uploading files.

The following code is throwing an error:

<!-- The template to display files available for upload -->¬
    152 <script id="template-upload" type="text/x-tmpl">¬
--  153     {% for (var i=0, file; file=o.files[i]; i++) { %}¬
|   154     <tr class="template-upload fade">¬
|   155         <td class="preview"><span class="fade"></span></td>¬
|-  156         <td class="name"><span>{%=file.name%}</span></td>¬

The above code is directly taken from the jquery upload library.

The error:

line 153, in template
    {% for (var i=0, file; file=o.files[i]; i++) { %}
TemplateSyntaxError: expected token ')', got 'i'

I think it is being caused due to the {% %} which is used by jinja2 as well as the text/x-tmpl js syntax. Is this correct? If so, How can I work around it? Please help.

I am using jinja2 templating language in my GAE-python project. I have tried to use the jquery-upload for uploading files.

The following code is throwing an error:

<!-- The template to display files available for upload -->¬
    152 <script id="template-upload" type="text/x-tmpl">¬
--  153     {% for (var i=0, file; file=o.files[i]; i++) { %}¬
|   154     <tr class="template-upload fade">¬
|   155         <td class="preview"><span class="fade"></span></td>¬
|-  156         <td class="name"><span>{%=file.name%}</span></td>¬

The above code is directly taken from the jquery upload library.

The error:

line 153, in template
    {% for (var i=0, file; file=o.files[i]; i++) { %}
TemplateSyntaxError: expected token ')', got 'i'

I think it is being caused due to the {% %} which is used by jinja2 as well as the text/x-tmpl js syntax. Is this correct? If so, How can I work around it? Please help.

Share Improve this question edited Aug 23, 2012 at 14:35 djc 11.7k5 gold badges43 silver badges54 bronze badges asked Aug 23, 2012 at 13:57 abhinavabhinav 3,2172 gold badges23 silver badges26 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

Try this:

{{ '{% for (var i=0, file; file=o.files[i]; i++) { %}' }}

Or you can use {% raw %} {% endraw %} blocks.

http://jinja.pocoo/docs/templates/#escaping

I've had problems while using Flask and Angular. That helped! Figured it might be helpful for other people.

http://flask-triangle.readthedocs/en/develop/tutorial/part1.html

本文标签: Jinja and javascript syntax conflictStack Overflow