Differences between revisions 3 and 4
Revision 3 as of 2009-10-12 03:19:44
Size: 1316
Editor: limodou
Comment:
Revision 4 as of 2009-10-12 03:20:20
Size: 1301
Editor: limodou
Comment:
Deletions are marked like this. Additions are marked like this.
Line 14: Line 14:
=== 1. 创建Project3项目 === === 创建Project3项目 ===
Line 20: Line 20:
=== 2. 创建Hello App === === 创建Hello App ===
Line 27: Line 27:
=== 3. 修改project3/apps/Hello/views.py === === 修改project3/apps/Hello/views.py ===
Line 40: Line 40:
=== 4. 在project3/apps/Hello/templates下创建index.html === === 在project3/apps/Hello/templates下创建index.html ===
Line 55: Line 55:
=== 5. 结束 === === 结束 ===

作者: limodou

题目要求

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

框架说明

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

步骤

在命令行下操作

创建Project3项目

uliweb makeproject project3

创建Hello App

cd project3
uliweb makeproject Hello

修改project3/apps/Hello/views.py

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

在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>

结束

测试

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)