3

以下、flask-wtfbootstrap-selectを組み合わせてみましたが、 TemplateSyntaxError: invalid syntax for function call expressionを修正しました

<form class="form-inline" action="/" method="POST" role="form">
<div class="input-group"> 
  {{ form.hidden_tag() }}
  <span class="input-group-addon">Make:</span>
  {{ form.make(id="make_select", class="selectpicker form-control", data-live-search="true") }}
  <span class="input-group-addon">Model:</span>
  {{ form.model(id="model_select", class="selectpicker form-control", data-live-search="true") }}

  <span class="input-group-btn">
    <button class="btn btn-default" type="submit">Search!</button>
  </span>
</div>
</form>

.

TemplateSyntaxError: invalid syntax for function call expression
Traceback (most recent call last):
  File "/home/mic/.virtualenvs/unisnp/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
  File "/home/mic/.virtualenvs/unisnp/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
  File "/home/mic/.virtualenvs/unisnp/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
  File "/home/mic/.virtualenvs/unisnp/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
  File "/home/mic/.virtualenvs/unisnp/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
  File "/home/mic/.virtualenvs/unisnp/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
  File "/home/mic/.virtualenvs/unisnp/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
  File "/home/mic/.virtualenvs/unisnp/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/mic/projects/unisnpdb/main.py", line 58, in decorated_function
body = render_template(template_name, **ctx)
  File "/home/mic/.virtualenvs/unisnp/lib/python2.7/site-packages/flask/templating.py", line 127, in render_template
return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
  File "/home/mic/.virtualenvs/unisnp/lib/python2.7/site-packages/jinja2/environment.py", line 830, in get_or_select_template
return self.get_template(template_name_or_list, parent, globals)
  File "/home/mic/.virtualenvs/unisnp/lib/python2.7/site-packages/jinja2/environment.py", line 791, in get_template
return self._load_template(name, self.make_globals(globals))
  File "/home/mic/.virtualenvs/unisnp/lib/python2.7/site-packages/jinja2/environment.py", line 765, in _load_template
template = self.loader.load(self, name, globals)
  File "/home/mic/.virtualenvs/unisnp/lib/python2.7/site-packages/jinja2/loaders.py", line 125, in load
code = environment.compile(source, name, filename)
  File "/home/mic/.virtualenvs/unisnp/lib/python2.7/site-packages/jinja2/environment.py", line 554, in compile
self.handle_exception(exc_info, source_hint=source)
  File "/home/mic/.virtualenvs/unisnp/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
reraise(exc_type, exc_value, tb)
  File "/home/mic/projects/unisnpdb/templates/search_page.tmpl", line 66, in template
{{ form.make(id="make_select", class="selectpicker form-control", data-live-search="true") }}
TemplateSyntaxError: invalid syntax for function call expression

.

from flask.ext.wtf import Form
from wtforms import SelectField


class VehicleForm(Form):
   make = SelectField(u'', choices=())
   model = SelectField(u'', choices=())

Why data-live-search"="true" is causing TemplateSyntaxError?

4

1 に答える 1

7

このスニペットを見てみましょう: http://flask.pocoo.org/snippets/107/

あなたの場合、次を置き換えます:

{{ form.make(id="make_select", class="selectpicker form-control", data-live-search="true") }}

{{ form.make(id="make_select", class="selectpicker form-control", **{'data-live-search':'true'}) }}
于 2014-10-03T07:38:12.453 に答える