render_template

时间:2018-04-06 10:51:23

标签: python flask syntax-error jinja2

<table>
    <thead>
        <th>Surname</th>
        <th>Forename</th>
        <th>Status</th>
        <th>Cluster</th>
        <th></th>
        <th></th>
    </thead>
    <tbody>         
        {% for s in staff %}            
        <tr>
            <td> {{ s.surname }} </td>
            <td> {{ s.forename }} </td>
            <td> {{ s.status }} </td>                   
            <td>
            {% for gc in grant_clusters %}      <!-- clusid  -->
                 {% if s.staff_id = lgi.staff_id %}                     
                        {{ gc.cluster_id }}
                 {% endif %}           
             {% endfor %}       

            </td>                   
            <td><a data-toggle="modal" href="#editstaff" class="staffedit" id="{{s.staff_id}}|{{s.forename}}|{{s.surname}}"> Edit </a></td>   
        <!--    <td><a data-toggle="modal" href="#removestaff" class="staffremove" id="{{s.staff_id}}|{{s.forename}}|{{s.surname}}"> Remove </a></td>  -->   
        </tr>                    
        {% endfor %}                        
    </tbody>
</table>

我正在尝试使用staff_id来选择匹配的cluster_id !!

ERROR:
jinja2.exceptions.TemplateSyntaxError: expected token 'end of statement block', got '='

Traceback:
Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\flask\app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Program Files\Python36\lib\site-packages\flask\app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "C:\Program Files\Python36\lib\site-packages\flask\app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Program Files\Python36\lib\site-packages\flask\_compat.py", line 33, in reraise
    raise value
  File "C:\Program Files\Python36\lib\site-packages\flask\app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Program Files\Python36\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Program Files\Python36\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Program Files\Python36\lib\site-packages\flask\_compat.py", line 33, in reraise
    raise value
  File "C:\Program Files\Python36\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Program Files\Python36\lib\site-packages\flask\app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Program Files\Python36\lib\site-packages\flask_login\utils.py", line 228, in decorated_view
    return func(*args, **kwargs)
  File "C:\inetpub\wwwroot\FlaskClive\theapp\routes.py", line 1006, in search_staff
    return render_template('search_staff.html', staff=r_s)
  File "C:\Program Files\Python36\lib\site-packages\flask\templating.py", line 133, in render_template
    return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
  File "C:\Program Files\Python36\lib\site-packages\jinja2\environment.py", line 869, in get_or_select_template
    return self.get_template(template_name_or_list, parent, globals)
  File "C:\Program Files\Python36\lib\site-packages\jinja2\environment.py", line 830, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "C:\Program Files\Python36\lib\site-packages\jinja2\environment.py", line 804, in _load_template
    template = self.loader.load(self, name, globals)
  File "C:\Program Files\Python36\lib\site-packages\jinja2\loaders.py", line 125, in load
    code = environment.compile(source, name, filename)
  File "C:\Program Files\Python36\lib\site-packages\jinja2\environment.py", line 591, in compile
    self.handle_exception(exc_info, source_hint=source_hint)
  File "C:\Program Files\Python36\lib\site-packages\jinja2\environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Program Files\Python36\lib\site-packages\jinja2\_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "C:\inetpub\wwwroot\FlaskClive\theapp\templates\search_staff.html", line 55, in template
    {% if s.staff_id = lgi.staff_id %}
  File "C:\Program Files\Python36\lib\site-packages\jinja2\environment.py", line 497, in _parse
    return Parser(self, source, name, encode_filename(filename)).parse()
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 896, in parse
    result = nodes.Template(self.subparse(), lineno=1)
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 878, in subparse
    rv = self.parse_statement()
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 130, in parse_statement
    return getattr(self, 'parse_' + self.stream.current.value)()
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 268, in parse_block
    node.body = self.parse_statements(('name:endblock',), drop_needle=True)
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 165, in parse_statements
    result = self.subparse(end_tokens)
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 878, in subparse
    rv = self.parse_statement()
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 130, in parse_statement
    return getattr(self, 'parse_' + self.stream.current.value)()
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 198, in parse_for
    body = self.parse_statements(('name:endfor', 'name:else'))
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 165, in parse_statements
    result = self.subparse(end_tokens)
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 878, in subparse
    rv = self.parse_statement()
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 130, in parse_statement
    return getattr(self, 'parse_' + self.stream.current.value)()
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 198, in parse_for
    body = self.parse_statements(('name:endfor', 'name:else'))
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 165, in parse_statements
    result = self.subparse(end_tokens)
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 878, in subparse
    rv = self.parse_statement()
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 130, in parse_statement
    return getattr(self, 'parse_' + self.stream.current.value)()
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 212, in parse_if
    'name:endif'))
  File "C:\Program Files\Python36\lib\site-packages\jinja2\parser.py", line 164, in parse_statements
    self.stream.expect('block_end')
  File "C:\Program Files\Python36\lib\site-packages\jinja2\lexer.py", line 386, in expect
    self.name, self.filename)
jinja2.exceptions.TemplateSyntaxError: expected token 'end of statement block', got '='

2 个答案:

答案 0 :(得分:0)

我想If语句应该有&#39; ==&#39;,试试并让我知道

答案 1 :(得分:0)

您的if条件不正确,您正在{% if s.staff_id = lgi.staff_id %}进行作业操作。它应该是{% if s.staff_id == lgi.staff_id %}