Differences between revisions 2 and 3
Revision 2 as of 2009-10-13 13:57:31
Size: 1476
Comment:
Revision 3 as of 2009-12-25 07:08:41
Size: 1480
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
[[TableOfContents]] <<TableOfContents>>
Line 80: Line 80:
attachment:image.jpg {{attachment:image.jpg}}

作者:hongqn

题目要求

CSS文件的引用,在模板中引入default.css

框架说明

Pylons (http://pylonshq.com)

步骤

在命令行下操作

1.创建Project4项目

paster create -t pylons project4

2.创建Hello controller

cd project4
paster controller hello

3.修改project4/controllers/hello.py

   1 def index(self):
   2     return render('/index.html')

4.在project4/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" />
  <link rel="stylesheet" type="text/css" href="${url('static', filename='default.css')}">
</head>
<body>
<h1>CSS Test</h1>
</body>
</html>

5.生成 default.css

创建project4/public/static/default.css文件,内容为:

h1 {border:1px solid #f00;}

6. 增加static route

在 config/routing.py 中 #CUSTOM ROUTES HERE 下增加

   1 map.connect('static', '/static/{filename:.*?}', _static=True)

7.结束

测试

cd project4
paster serve --reload development.ini

访问 http://localhost:5000/hello/index

结果如下:

[ATTACH]

说明

pylons直接在public中寻找静态文件

PylonsCssFileGenerateStaticPath (last edited 2009-12-25 07:08:41 by localhost)