1. 程式人生 > >模版繼承

模版繼承

imp ext foo con xtend footer head debug extend

from flask import Flask, render_template


app = Flask(__name__)

@app.route("/one")
def get_one():
    return render_template("one.html")

@app.route("/two")
def get_two():
    return render_template("two.html")



if __name__ == __main__:
    app.run(debug=True)


#base.html
<!DOCTYPE html>
<html lang="
en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div>Header</div> <div> {% block content %} {% endblock %} </div> <div>Footer</div> </body> </html> #one.html
{% extends "base.html" %} {% block content %} <h2>這恐怕是第一頁</h2> {% endblock %} #two.html {% extends "base.html" %} {% block content %} <h2>這應該是第二頁</h2> {% endblock %}

模版繼承