python - UndefinedError when trying to call function in Jinja templaet -
in view function, pass dict variable html file. tags
dictionary default {int: []}
. value of each key list, use iteritems()
show every item in list. however, didn't work, got error undefinederror: 'tags' undefined
. jinja2 able call functions in html? why didn't code work?
return render_template('index.html', title='home', user=user, posts=posts, tags=tags)
<div class="post-tag"> {% key,tag in tags.iteritems() %} <a href="#">{{tag}}</a> {% endfor %} </div>
personally i've never used flask i've used jinja2 cherrypy. code absolutely correct. how works think happening variable tags
not defined when rendering template. have here
all basic datatype operations available in jinja2. check if tags
not being defined in if condition you're not entering in particular case.
{% k, v in dct.iteritems() %}<a href="#">{{k}}</a>{% endfor %}
outputs
<a href="#">item1</a><a href="#">item2</a>
Comments
Post a Comment