标签:
<html> <title>{{title}} - myblog</title> <body> <h1>Hello,{{user.nickname}}</h1> </body> </html>
from flask import render_template from app import app @app.route('/') @app.route('/index') def index (): user={'nickname':'Bob'} return render_template("index.html", title="Home", user=user) #从flask导入render_template #render_template(html文件,需要传数据的变量)
<html> {% if title %} <title>{{title}} - myblog</title> {% else %} <title>Welcome - myblog</title> {% endif %} <body> <h1>Hello,{{user.nickname}}</h1> </body> </html>
from flask import render_template from app import app @app.route('/') @app.route('/index') def index (): user={'nickname':'Bob'} posts=[ {'author':{'nickname':'John'}, 'body':'Beautiful day in Portland!'}, {'author':{'nickname':'Susan'}, 'body':'The Avengers movie was so cool!'} ] return render_template("index.html", title="Home", user=user, posts=posts)
<html> {% if title %} <title>{{title}} - myblog</title> {% else %} <title>Welcome - myblog</title> {% endif %} <body> <h1>Hello,{{user.nickname}}</h1> {% for post in posts %} <p>{{ post.author.nickname }} says:<b>{{post.body}}</b></p> {% endfor %} </body> </html>
<html> <head> {% if title %} <title>{{title}} - myblog</title> {% else %} <title>Welcome - myblog</title> {% endif %} </head> <body> <div>MyBlog:<a href="/index">Home</a></div> <hr> {% block content %} {% endblock%} </body> </html>
{% extends "base.html" %} {% block content %} <h1>Hello,{{user.nickname}}</h1> {% for post in posts %} <p>{{ post.author.nickname }} says:<b>{{post.body}}</b></p> {% endfor %} {% endblock %}
标签:
原文地址:http://blog.csdn.net/u013055678/article/details/51365740