Differences between revisions 2 and 3
Revision 2 as of 2009-10-12 03:18:07
Size: 1172
Editor: limodou
Comment:
Revision 3 as of 2009-10-12 03:19:44
Size: 1316
Editor: limodou
Comment:
Deletions are marked like this. Additions are marked like this.
Line 55: Line 55:
=== 6. 结束 === === 5. 结束 ===
Line 67: Line 67:

== 说明 ==

Uliweb中也有url_for函数,但是在启动uliweb服务时会自动添加到模板的运行环境中,不需要导入。

作者: limodou

题目要求

url_for方式使用,在模板中动态实现url

框架说明

Uliweb (http://code.google.com/p/uliweb)

步骤

在命令行下操作

1. 创建Project3项目

uliweb makeproject project3

2. 创建Hello App

cd project3
uliweb makeproject Hello

3. 修改project3/apps/Hello/views.py

   1 @expose('/')
   2 def index():
   3     return {}
   4 
   5 @expose('/test')
   6 def test():
   7     return "test href link"

4. 在project3/apps/Hello/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>
<a href="{{=url_for('Hello.views.test')}}"> test_url_for</a>
</body>
</html>

5. 结束

测试

cd project3
uliweb runserver

访问 http://localhost:8000/

进入连接在超链接上放置鼠标,可以在浏览器底部看到test_url_for所指向的连接地址: http://localhost:8000/test

说明

Uliweb中也有url_for函数,但是在启动uliweb服务时会自动添加到模板的运行环境中,不需要导入。

UliwebUrlFor (last edited 2009-12-25 07:15:44 by localhost)