flask jinjia模板语法 字典,字符串过滤

from flask import Flask
from flask import render_template

app = Flask(name)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/user/')
def user(name):
mydict={'key':'key'}
return render_template('user.html', name=name,mydict=mydict)

if name == 'main':
app.run()






Title


Hello, {{ name }}!


HELLO,{{ mydict['key']|capitalize }}


HELLO,{{ mydict['key']|upper }}


{% if user %}
Hello, {{ user }}!
{% else %}
Hello, Stranger!
{% endif %}

    {% for comment in comments %}
  • {{ comment }}

  • {% endfor %}

使用宏

{% macro render_comment(comment) %}

  • {{ comment }}

  • {% endmacro %}

      {% for comment in comments %}
      {{ render_comment(comment) }}
      {% endfor %}


    {% include 'common.html' %}

    block占位符



    {% block head %}
    {% block title %}{% endblock %} - My Application
    {% endblock %}


    {% block body %}
    {% endblock %}

    extends

    {% extends "base.html" %}
    {% block title %}Index{% endblock %}
    {% block head %}
    {{ super() }}

    {% endblock %}
    {% block body %}

    Hello, World!


    {% endblock %}

    你可能感兴趣的:(flask jinjia模板语法 字典,字符串过滤)