LoginSignup
0
2

More than 3 years have passed since last update.

FLASK routineを使ってテンプレート作成【Windows.ver】

Last updated at Posted at 2019-05-26

1.新規フォルダ(templetes)を作成
保存名はtemplates 複数形!(templateの単数形ではないので注意)

2.templates フォルダの中に
index.htmlファイルを作成
2019-05-27 (8).png

3.index.htmlのコードは下記のように記述する
2019-05-27 (9).png

3.下記のようにrender_templateと一行目に追記することでtemplateが呼び出せる。
2019-05-27 (7).png

  nameを指定する
  return のところで"index.html"の後にname_value=nameを追記

4.ブラウザを開くとテンプレートが表示される
2019-05-27 (11).png

さらにStep up!
index.htmlファイルの中に
{% if文 %}でpythonコードを記述できる

書き方見本2019-06-20 (2).png

{%if name_value %}
hello.pyファイルの中で
nameが指定されていたら、nameが表示される
⇒この場合はHello Flaskが表示される

{% else %}
hello.pyファイルの中で
nameが指定されていなかったら
Hi, This is a penと表示される

{% endif %}
if文を終了させるための命令

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2