Flask インスタンスを run 実行するスクリプトと同じ階層にあるフォルダ名
templates ・・・HTMLを置くフォルダ
static ・・・CSS, JSを置くフォルダ
デフォルトの構成
/root
|
+--- static
| |
| +--- common.css
| +--- common.js
|
+--- templates
| |
| +--- index.html
| +--- layout.html
|
+---- run.py
index.html
{% extends "layout.html" %} {% block content %} Message : {{message}} {% endblock %}
layout.html
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>{{title}}</title> </head> <body> {% block content %} {% endblock %} </body> </html>
run.py
from flask import Flask, render_template @app.route('/') def home): msg = 'メッセージ' return render_template("hello.html", title='Home', message=msg) if __name__ == '__main__': app.run(port=80, debug=True)
がデフォルトであるが、
これを変える方法、
template_folder 、static_folder を指定して変更する
app = Flask(__name__, template_folder='templates', static_folder='static')