• Index

模板

Reads: 2067 Edit

templates/base.html

<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}{% endblock %} -我的网站</title>
</head>
<body>
{% block body %}
    这是基类中的内容
{% endblock %}
</body>
</html>

templates/index.html

{% extends "base.html" %}
{% block title %}网站首页{% endblock %}
{% block body %}
    {{ super() }}
<h4>这是网站首页的内容!</h4>
{% endblock %}

templates/product.html

{% extends "base.html" %}
{% block title %}产品列表页{% endblock %}
{% block body %}
<h4>这是产品列表页的内容!</h4>
<h4> 取得网页标题的内容:   {{ self.title() }}</h4>
 {{ super() }}
{% endblock %}

app.py

from flask import Flask,render_template
app = Flask(__name__)

# http://127.0.0.1:5000/
@app.route('/')
def index():
    return render_template('index.html')

#  http://127.0.0.1:5000/product
@app.route('/product')
def product():
    return render_template('product.html')
if __name__ == '__main__':
    app.run(debug=True)


Comments

Make a comment

www.ultrapower.com ,王硕的博客,专注于研究互联网产品和技术,提供中文精品教程。 本网站与其它任何公司及/或商标无任何形式关联或合作。
  • Index
aaaaa