【发布时间】:2014-05-10 23:26:03
【问题描述】:
我是模板引擎的新手,需要更聪明的人的帮助。尝试使用 Flask 模板生成搜索结果,遇到了很多痛苦。烧瓶:
@app.route('/*?search', methods=['POST', 'GET'])
if request.method == 'GET':
if request.args.get('q'):
qList = re.sub("[^\w]", " ", request.args.get('q') ).split()
htmlA = """
<div class="results" >
<p>
"""
htmlB = """
</p>
<br></br>
</div>
"""
found = None
for it in qList :
found = htmlA + RESULT_BLAH_BLAH_METHOD( it ) + htmlB
return render_template( 'list_of_found_items.html', found=found )
和html模板部分:
<somewhere in html>
{% block content %}
{{ found }}
{% endblock %}
</somewhere in html>
这样,即使结果存在并通过打印到控制台输出进行检查,结果也不会显示在页面上。我错过了什么?谢谢。
【问题讨论】:
-
什么是
L?是空的吗? -
rez应该是什么? -
谢谢。我刚刚编辑过,但没有显示出来。
-
render_template('...', found)=>render_template('...', found=found)否则模板不知道found是什么。 -
这是因为自动转义。 flask 认为您的格式(围绕 qList 值的 for 循环)应该在模板中。将 qList 直接传递给您的模板并在那里进行格式化。
标签: python django-templates flask jinja2 templating