Okay so we got rid of this form HTML, let's just
get rid of this altogether, and let's see if our basic
scaffolding is working. So, instead of doing all that other stuff
we were doing down there, let's just say, self.render, that's the new
function we just added. Shopping_list.html, so this should just render that
empty form, and then we'll go ahead and comment out the
rest of this. Okay, and we'll take all of this other,
other junk that we were doing before, and and we'll comment it
out for now. Okay, let's go to our browser and
make sure this works. Okay. I reloaded the page, and we
have our add food thing again. And if I add
foods, we can see them getting added to the URL, but
since we don't have any of that that hidden input
trick and we're not pulling things off our parameters anymore, it's
just replacing the one item in the URL. But that basically
shows our template is working end to end. Okay, so hopefully
you were able to follow along with me through that. I
know, I know it's kind of tedious, but now that we have
the scaffolding up, we can actually start using these templates. So
let's go ahead and learn a few things about Jinja templates.
ではfrom_htmlを削除して
テンプレートがうまく動作するか確認しましょう。
前まではHTML生成のために色々なコードを書く必要がありましたが
今は先ほど追加したファンクションを書くだけです。
self.render("shopping_list.html")
これで空のフォームがレンダリングされるはずです。
余計なコードはコメントアウトしておきましょう。
OK、コードのこの部分
これは前に書いた不要なコードなのでコメントにします。
OK、ブラウザを見て見ましょう。
正しく動作しているでしょうか。
ページをリロードすると"Add a Food"ページが見えました。
食品名を追加するとURLに食品名が追加されます。
しかしまだhidden input は設定していません。
ですからパラメータは複数保持できません。
パラメータは毎回置き換えられます。
でもテンプレートが基本的に動作していることを確認できました。
自分のパソコンでも動作することを確認してください。
少し回りくどい説明だったかもしれませんが、
テンプレートを使ったHTMLの生成ができるようになりました。
それではさらに詳しくjinja2の使い方を学習しましょう。