base:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>知了课堂</title> </head> <body> <p>我是父母版中的</p> {% block body_block %} {% endblock %} </body> </html>
index:
{% extends 'base.html' %} {% block body_block %} 我是 body_block中的代码 {% endblock %}
.py
from flask import Flask,render_template app = Flask(__name__) app.config.update(TEMPLATE_AUTO_RELOAD=True) @app.route('/') def index(): return render_template("index.html") @app.route('/detail/') def my_list(): return render_template("course_detail.html") if __name__ == '__main__': app.run(debug=True)