名前を名乗ろう

□未翻訳

□翻訳中

□翻訳完了(細田謙二)

■レビュー(中垣健志)

名前を名乗ろう

ここでは、2つのページ(最初と2番目)を作成します。最初のページはフォームを作成し、訪問者の名前を尋ね、第2のページへリダイレクトします。第2のページは訪問者に名前で挨拶します。

Now create two pages (first and second), where the first page creates a form, asks the visitor's name, and redirects to the second page, which greets the visitor by name.

デフォルトのコントローラに対応するアクションを書きます:

Write the corresponding actions in the default controller:

1.

2.

3.

4.

5.

def first():

return dict()

def second():

return dict()

そして、最初のアクションに対する"default/first.html"ビューを作成します:

Then create a view "default/first.html" for the first action:

そして、以下を入力します:

and enter:

1.

2.

3.

4.

5.

6.

{{extend 'layout.html'}}

What is your name?

<form action="second">

<input name="visitor_name" />

<input type="submit" />

</form>

最後に、第2のアクションに対する"default/second.html"ビューを作成します:

Finally, create a view "default/second.html" for the second action:

1.

2.

{{extend 'layout.html'}}

<h1>Hello {{=request.vars.visitor_name}}</h1>

両方のビューにおいて、web2pyに用意されている基本的な"layout.html"ビューが拡張されています。このレイアウト・ビューは、2つのページのルック&フィールの一貫性を保ちます。レイアウト・ファイルは主にHTMLコードにより構成されているので、簡単に編集や置き換えができます。

In both views we have extended the basic "layout.html" view that comes with web2py. The layout view keeps the look and feel of the two pages coherent. The layout file can be edited and replaced easily, since it mainly contains HTML code.

最初のページを開いて、あなたの名前を入力してください:

If you now visit the first page, type your name:

そして、フォームをサブミットしてください。すると、挨拶が表示されます:

and submit the form, you will receive a greeting: