libro
www.tuyano.com
PythonによるGoogle App Engine(GAE)プログラミング入門

複数モデルの連携処理 (4/6)

作成:2010-01-08 10:58
更新:2010-05-10 21:59

■memberのビューを作成する

では、ビューとなるテンプレートファイルを作成しましょう。まずはメンバーの登録と表示を行うmember.htmlからです。以下のリストのように記述をしておきましょう。

ここでは、{% for data in datas %}というように、コントローラーから渡された配列datasから順にオブジェクトを取り出し、それをもとにして{{data.key.id}}というように個々のデータを出力しています。またフォームは、action="/member"に送信するようにしています。

※プログラムリストが表示されない場合

AddBlockなどの広告ブロックツールがONになっていると、プログラムリスト等が表示されない場合があります。これらのツールをOFFにしてみてください。

●プログラム・リスト●

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
		xml:lang="ja" lang="ja">
	<head>
		<meta http-equiv="Content-Type"
			content="text/html; charset=UTF-8" />
		<title>Member</title>
	</head>
	<body>
		<h1>Member Page</h1>
		<form method="post" action="/member">
		<table>
			<tr>
			<th>名前:</th>
			<td><input type="text" name="name" /></td>
			</tr>
			<tr>
			<th>電話:</th>
			<td><input type="text" name="tel" /></td>
			</tr>
			<tr>
			<th>コメント:</th>
			<td><textarea name="comment"></textarea></td>
			</tr>
			<tr><th></th>
			<td><input type="submit" value="送信" /></td></tr>
		</table>
		</form>
		<hr />
		<table border="1" width="500px">
		<tr>
		<th width="50px">ID</th>
		<th width="200px">メンバー</th>
		<th width="200px">アカウント</th>
		<th width="100px">電話</th>
		</tr>
		{% for data in datas %}
		<tr>
		<td>{{data.key.id}}</td>
		<td>{{data.name}}</td>
		<td>{{data.user.nickname}}</td>
		<td>{{data.tel}}</td>
		</tr>
		{% endfor %}
		</table>
	</body>
</html>

※関連コンテンツ

「PythonによるGoogle App Engine(GAE)プログラミング入門」に戻る