Differences between revisions 1 and 3 (spanning 2 versions)
Revision 1 as of 2009-09-30 06:17:40
Size: 1016
Comment:
Revision 3 as of 2009-09-30 06:36:16
Size: 1028
Comment:
Deletions are marked like this. Additions are marked like this.
Line 28: Line 28:
#!python
Line 43: Line 44:
<h1>Hello, ${name}</h1> <h1>Hello, ${c.name}</h1>

题目要求

写一个Hello,template程序,使用模板来显示Hello,{name},其中name是变量,要由外部传入

框架说明

Pylons (http://pylonshq.com)

步骤

在命令行下操作

1. 创建Project2项目

paster create -t pylons project2

2. 创建Hello App

cd project2
paster controller hello

3. 修改project2/controllers/hello.py

   1 def index(self):
   2     c.name = 'template'
   3     return render('/index.html')

4. 在project2/templates下创建index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>Hello World</title>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>Hello, ${c.name}</h1>
</body>
</html>

5. 结束

测试

cd project2
paster serve --reload development.ini

访问 http://localhost:5000/hello/index 即可。

PylonsHelloTemplate (last edited 2009-12-25 07:14:11 by localhost)