1. 程式人生 > 其它 >flask-python-html表格

flask-python-html表格

技術標籤:python-flask-html 表格問題htmlpythonflask

#!/usr/bin/env python3
# -*- coding:utf-8 -*-
#test.py檔案 
import json
from flask import Flask, render_template
 
app = Flask(__name__)
 
@app.route("/")
@app.route("/index.html")
def index():
    # flask_data = 'Hello Flask!'
    flask_data=
'name' flask_data_01='username' flask_data_02='zhaoqian' flask_data_03='danys' # return render_template('index.html', flask_data=flask_data) return render_template('index.html', flask_data=flask_data,flask_data_01=flask_data_01,flask_data_02=flask_data_02,flask_data_03=flask_data_03) #result=app.index()
#print(result) if __name__ == '__main__': app.run(debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test</title>
</head>
<body>
 
<!-- <h1>{{ flask_data }}</h1> -->
<table border='1'>
<tr> <th>{{ flask_data }}</th> <th>{{ flask_data_01 }}</th> </tr> <tr> <td>{{ flask_data_02 }}</td> <td>{{ flask_data_03 }}</td> </tr> </table> </body> </html>在這裡插入程式碼片

在templates資料夾下的HTML檔案
在這裡插入圖片描述

最終結果
在這裡插入圖片描述