uliweb 如何指定模板

6 views
Skip to first unread message

Asins

unread,
Oct 23, 2009, 6:19:20 AM10/23/09
to uli...@googlegroups.com
在看uliweb的介绍,看到第四章时有这么一段,
@expose('/show')
def show():
    return {}

    这个show()函数就很简单了。它映射到'/show'上,并且最后返回了一个空dict对象。那么说明,我们将要使用模板了。


有两个问题想了解下:

1、在这里面是哪个变量指引着到/templates目录查找show.html文件的?是expose('/show')中的show还是def show()这函数名?

2、能否自己指定使用的模板?如果能又是如何指定呢?

limodou

unread,
Oct 23, 2009, 6:51:16 AM10/23/09
to uli...@googlegroups.com
2009/10/23 Asins <lwk...@gmail.com>:

当返回一个dict对象时,uliweb会自动根据view函数的名字,如上面是'show',自动匹配一个叫'show.html'的模板。是def后面的东西。

>
> 2、能否自己指定使用的模板?如果能又是如何指定呢?
>

可以指定。通过在返回前指定:

response.template = 'other.html'


--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
UliWeb <<simple web framework>>: http://uliwebproject.appspot.com
My Blog: http://hi.baidu.com/limodou

Chunlin Zhang

unread,
Nov 28, 2012, 4:15:46 AM11/28/12
to uli...@googlegroups.com


在 2009年10月23日星期五UTC+8下午6时51分16秒,limodou写道:
2009/10/23 Asins <lwk...@gmail.com>:
> 在看uliweb的介绍,看到第四章时有这么一段,
>
> @expose('/show')
> def show():
>     return {}
>
>     这个show()函数就很简单了。它映射到'/show'上,并且最后返回了一个空dict对象。那么说明,我们将要使用模板了。
>
> 有两个问题想了解下:
>
> 1、在这里面是哪个变量指引着到/templates目录查找show.html文件的?是expose('/show')中的show还是def
> show()这函数名?

当返回一个dict对象时,uliweb会自动根据view函数的名字,如上面是'show',自动匹配一个叫'show.html'的模板。是def后面的东西。

>
> 2、能否自己指定使用的模板?如果能又是如何指定呢?
>

可以指定。通过在返回前指定:

response.template = 'other.html'

这个指定template的建议整理到文档里去,刚才想查这个找了好久 

limodou

unread,
Nov 28, 2012, 9:03:51 AM11/28/12
to uli...@googlegroups.com
文档是写在 http://uliweb.readthedocs.org/en/latest/views.html 中的,可能不是说明的很明显。回头我改一下,看说明更明显一些。


2012/11/28 Chunlin Zhang <zhangc...@gmail.com>



--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
UliWeb <<simple web framework>>: https://github.com/limodou/uliweb
My Blog: http://my.oschina.net/limodou

Chunlin Zhang

unread,
Nov 28, 2012, 9:25:40 AM11/28/12
to uli...@googlegroups.com
原来是这里啊,我一想是和template相关的就跑到"模板(Template)"这里去找了

2012/11/28 limodou <lim...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages