【发布时间】:2020-06-07 22:03:42
【问题描述】:
在 Flask 中并使用 Jinja2,我调用了一个数据列表,但由于某种原因,任何带有空格的选项都会被修剪,因此“番茄酱”变成了“番茄”。这是 Flask 正在做的事情还是我搞砸了模板?
<!-- HOMEPAGE -->
<form type="text" id="homeForm" class="centered" method="post" onsubmit="return false;">
{{ form.hidden_tag() }}
<input type="text" id="homeInput" autocomplete=off list="topps" placeholder="Input here">
<datalist id="topps">
{% for top in topps %}
<option value={{ top }}>
{% endfor %}
</datalist>
<button type="submit" id="homeSubmit">Submit</button>
</form>
# ROUTES.PY #
@app.route('/', methods=['GET', 'POST'])
@app.route('/index', methods=['GET', 'POST'])
def index():
form = ToppingsForm()
topps = ["tomato sauce", "chilli flakes","something else"]
return render_template('index.html', title='Home', form=form, topps=topps)
【问题讨论】:
标签: html flask jinja2 flask-wtforms datalist