手记

flask 显示四大名著

'''
在页面上面显示四大名著
'''

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def index():
    books = [
        {
            'book_name': '西游记',
            'author': '吴承恩'
        },
        {
            'book_name': '红楼梦',
            'author': '曹雪芹'
        },
        {
            'book_name': '水浒传',
            'author': '施耐庵'
        },
        {
            'book_name': '三国演义',
            'author': '罗贯中'
        }
    ]
    return render_template('index.html', books=books)

if __name__ == "__main__":
    app.run(debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>四大名著</title>
</head>
<body>
<table border="1" cellpadding="0">
    <tr>
        <th>书名</th>
        <th>作者</th>
    </tr>
    {% for book in books %}
    <tr>
        <td>{{book.book_name}}</td>
        <td>{{book.author}}</td>
    </tr>
    {% endfor %}
</table>
</body>
</html>
2人推荐
随时随地看视频
慕课网APP

热门评论

1、python3 flask mysql
2、创建数据库务必指定数据库编码 character set utf8
3、连接数据库信息
4、继承db 的模型
5、主键
6、唯一键
7、外键
8、打印信息
9、添加数据,注意一定要提交
10、查询数据库中的数据,在模板中显示
11、模板中的for 循环,字段需要跟表中的字段进行对应
12、怎么查询所有数据

查看全部评论