Differences between revisions 1 and 3 (spanning 2 versions)
Revision 1 as of 2009-10-12 03:16:41
Size: 1946
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 40: Line 40:

=== 4. 修改project3/apps/settings.ini ===


{{{
#INSTALLED_APPS = [
# 'uliweb.contrib.staticfiles',
# ]}}}
改为:
{{{
INSTALLED_APPS = [
    'uliweb.contrib.staticfiles',
    'Hello',
    ]
}}}

=== 5. 在project3/apps/Hello/templates下创建index.html ===
=== 4. 在project3/apps/Hello/templates下创建index.html ===
Line 71: Line 55:
=== 6. 结束 === === 5. 结束 ===
Line 84: Line 68:
== 使用admin功能配置app == == 说明 ==
Line 86: Line 70:
除了上面手工添加app到INSTALLED_APPS之外,还可以使用uliweb的admin功能来添加,步骤如下:

=== 启动admin界面 ===

在命令行下:

{{{
cd project3
uliweb runadmin
}}}

然后访问 http://localhost:8000/admin

=== 配置 ===

 * 点击build tab页
 * 再选择App Configure页
 * 选中 No Catalog 中的Hello(Hello)
 * 选中 System Apps 中的 staticfiles(uliweb.contrib.staticfiles)

选中后的结果将自动保存到project3/apps/settings.ini中。
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)