Sample manma
python
>>> from jinja2 import Template
>>> template = Template('Hello {{ name }}!')
>>> template.render(name='John Doe')
u'Hello John Doe!'
or render to {'name':'John Doe'}
for loop with ipython
python
from jinja2 import Template
str_temp = """
<title>{% block title %}{% endblock %}</title>
<ul>
{% for user in users %}
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
{% endfor %}
</ul>
"""[1:-1]
template = Template(str_temp)
data = [ { 'url': 'imaoka.click', 'username': 'imaoka'} ]
template.render(users=data)
> u'<title></title>\n<ul>\n\n <li><a href="gimaoka.click">imaoka</a></li>\n\n</ul>'
Ignore {% block}
ʻUsers instead of ʻuser
data.append({'url': 'hogehoge' ...
Add it with etc. and try it
I often use it in shell scripts like {#
, but it's no good
{{'Problem part'}}
You can escape like
http://qiita.com/swfz/items/63b3036a44829f201001
block It seems to be used for template inheritance Write someday
Recommended Posts