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)





本文通过一个具体的示例介绍了如何使用Flask框架进行模板继承,包括基本模板的定义和子模板的扩展方法。
305

被折叠的 条评论
为什么被折叠?



