懒龙谷
  • Home
  • Categories
  • Tags
  • Archives

python web框架html模板

Contents

  • 语法

语法

  1. 变量 {{var}} , render _ template("index.html", title = 'Home', user = user)
  2. 控制

    {% if title %}
    <title>{{title}} - microblog</title>
    {% else %}
    <title>Welcome to microblog</title>
    {% endif %}
    
  3. 循环

    {% for post in posts %}
    <p>{{post.author.nickname}} says: <b>{{post.body}}</b></p>
    {% endfor %}
    
  4. 模板继承

    1. super(base.html):
      其他内容 + {% block content %}{% endblock %} 如base 里面定义导航栏, 其他页面用 block content 扩展其他内容
    2. sub(index.html):
      {% extends "base.html" %} {% block content %}

      Hi, {{user.nickname}}!

      {% for post in posts %}

      {{post.author.nickname}} says: {{post.body}}

      {% endfor %}

this guy is lazy, nothing leave

Comments
comments powered by Disqus

  • « controller.mkd
  • 标准库functools »

Published

Sep 5, 2014

Category

web

Tags

  • flask 1
  • python 4
  • web 2

Stay in Touch

  • Powered by Pelican. Theme: Elegant by Talha Mansoor