以下の内容はhttps://a1026302.hatenablog.com/entry/2024/05/10/173720より取得しました。


【Flask】render_template を使ってみました

Flask で render_template を使ってみたので、ここにメモを残します。

サンプルコード

python

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

@app.route('/index')
def index():
    foo = "sample 01"
    bar = "sample 02"
    return render_template('index.html', foo=foo, bar=bar)

if __name__ == '__main__':
    app.run()

html

「 {{ xxx }} 」で渡した変数を囲うと変数の中身が表示できます。

<html>
    <head>
    </head>
    <body>
    this is the index page. {{ foo }} / {{ bar }}
    </body>
</html>

メモ

  • デフォルト html ファイルは templates フォルダに格納
  • テンプレートフォルダはデフォルトアプリケーションと同じ階層にtemplates フォルダを作る



以上の内容はhttps://a1026302.hatenablog.com/entry/2024/05/10/173720より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14