python - Rendering database results in Jinja seems to add extra {} characters -


i want render results sqlite database query in template. however, {colintitule': u'i icecream'}. don't want {} or column name. how render correctly?

def query_db(query, args=(), one=false):     cur = g.db.execute(query, args)     rv = [dict((cur.description[idx][0], value) idx, value in enumerate(row)) row in cur.fetchall()]     return (rv[0] if rv else none) if 1 else rv  @app.route('/toto') def toto():     entries = query_db("select colintitule toto col1 = 1")     return render_template('show_results.html', entries = entries)    

show_results.html:

{% extends "layout.html" %} {% block body %} <ul class=entries>     {% entry in entries %}     <li><h2>{{ entry }}</h2>     <br>     {% else %}     <li><em>no entry here</em>     {% endfor %} </ul> {% endblock %} 

entries list of dict objects when print them in template using {{ entry }}, printing dict repr.

your template should more this

{% extends "layout.html" %} {% block body %} <ul class=entries>     {% entry in entries %}     <li><h2>{{ entry["colintitule"] }}</h2>     <br>     {% else %}     <li><em>no entry here</em>     {% endfor %} </ul> {% endblock %} 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -