学以致用

focus on Python , C++, and some interest in Go and R

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

2012年3月6日

摘要: 在使用web.py进行开发的时候避免不了会在template中使用$code来定义一些小函数,按照web.py的文档来看,$code之内能包含任意的python代码,但在实际使用的时候却经常发现不是这个样子的,只有特定的函数可以在$code中出现,比如说默认情况下在template中可以使用 len 函数,但却不能使用 str,为什么?仔细分析web.py的源码可以发下:所有有关template处理的都包含在template.py文件中。调用template最终会调用到BaseTemplate 的_compile方法,其中_compile的实现细节为def _compile(self, cod 阅读全文
posted @ 2012-03-06 14:17 Jerry.Kwan 阅读(992) 评论(0) 推荐(0) 编辑