Flask+ テーブルの静的表示

Python Web 開発 (継続的に更新されています...)
神は沈黙しています - 個人的な CSDN ブログ投稿ディレクトリ

この記事の要件シナリオは次のとおりです: 現在、JSON 形式のテーブルがあります。特定の形式は重要ではありません。他の形式のテーブルを変更する方法は理解できると思います。つまり、Python+Flask を使用してこのフォームを抽出し、HTML ページに表示したいと考えています。

最終的なレンダリング効果 (まったく美化されていません):
ここに画像の説明を挿入

1. HTMLセクション

カンファレンス.html

<!DOCTYPE html>
<html>
<head>
    <title>Table</title>
</head>
<body>
    <table>
        <thead>
            <tr>
                {% for header in headers %}
                    <th>{
   
   { header }}</th>
                {% endfor %}
            </tr>
        </thead>
        <tbody>
            {% for row in rows %}
                <tr>
                    {% for cell in row %}
                        <td>{
   
   { cell }}</td>
                    {% endfor %}
                </tr>
            {% endfor %}
        </tbody>
    </table>
</body>
</html>

2.Pythonコード部分

@app.route('/conference',methods={
    
    'GET','POST'})
def conference():
    table_json=json.load(open('conference_recommendation/conference_information.json'))
    
    headers=['会议简称','学科','会议级别','会议全称','2023年官网','2023年DDL','DBLP官网']
    rows=[]
    for k in table_json:
        for sample in table_json[k]:
            row=[]
            row.append(sample['conference_jiancheng'])
            row.append(k)
            row.append(sample['rate'])
            row.append(sample['conference_quancheng'])
            row.append(sample['official_site'])
            row.append(sample['deadline'])
            row.append(sample['dblp_official_site'])
            rows.append(row)

    return render_template('conference.html', headers=headers, rows=rows)

3. この記事の執筆過程で参照したその他のネットワーク資料

実際、中心的な参照資料は ChatGPT です...

  1. HTML テーブルの基礎 - Web 開発を学ぶ | MDN
  2. learning-area/personal-pronouns.html メイン · mdn/learning-area · GitHub
  3. Windows Python フラスコがファイル データを読み取り、テーブルを返す - Alibaba Cloud Developer Community

おすすめ

転載: blog.csdn.net/PolarisRisingWar/article/details/130995855