genshi渲染lribeiro.cherrypy.templating

lribeiro.cherrypy.templating.genshi的Python项目详细描述


用于lribeiro.cherrypy.templating

的genshi渲染器

它有三个可选配置项:

  • templating.genshi.template_目录:可以是templates目录的路径、路径列表或genshi.template.TemplateLoader接受的任何内容。如果没有给定,则使用{root module directory}/templates作为模板目录。
  • templating.genshi.loader_选项:dict包含传递给templateloader构造函数的其他参数
  • templating.genshi.render_选项:dict包含呈现模板时使用的参数,例如,{'method':'html','doctype':'html transitional'}

您还可以通过@templatedecorator args和kwargs向呈现传递参数。

classController:@cherrypy.expose@template('template_name.html',method='xhtml',doctype='xhtml11')defhandler(self):pass

设置模板名称时,请记住genshi将前导斜杠解释为绝对路径!因此,下面可能会生成一个模板notfound:

classWrongController:@cherrypy.expose# pay attention to the leading slash# Genshi will look for a 'wrong_template_name.html' file on the root of the filesystem@template('/wrong_template_name.html')defwrong_handler(self):pass

在python3.4下开发,并对python2.7、python3.4和pypy进行了测试。

用法:

importcherrypyfromlribeiro.cherrypy.templatingimporttemplatefromlribeiro.cherrypy.templating.genshiimportrendererclassRoot(object):@cherrypy.expose@template('index.html')defindex(self):return{'context':'variables'}@cherrypy.expose@template('/var/templates/page.html')# absolute pathdefpage(self):return{'context':'variables'}config={'/':{'templating.renderer':renderer,'templating.genshi.template_directories':['templates',# relative to the module where the root class was declared'/var/templates'# absolute path],'templating.genshi.loader_options':{'default_encoding':'utf-8'},# this is optional'templating.genshi.render_options':{'method':'html','doctype':'html5'}# this is also optional}}if__name__=='__main__':cherrypy.quickstart(Root(),'/',config)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java从浏览器获取URL   JRMP连接建立期间发生java错误   SpringJava。lang.NoClassDefFoundError:org/springframework/beans/factory/BeanNameAware   垃圾收集如何在Java中(有效地)删除最终数组   当您不拥有模型时,java实现MVP?   java Eclipse无法编译粘贴的代码   java一个单元如何测试非确定性加密函数?   java捕获错误消息并显示在控制台(IDE)中   java如何减少完整GC的数量?   java生成axis2 Web服务客户端jar   java列表<List<Integer>>到2D数组的转换(int[]   java安全。getString(mContext.getContentResolver(),“bluetooth_address”)在Android O中返回null   java如何从TCP数据包中获取HTTP正文   base64中带有内联附件的java提取电子邮件正文   java如何使用SQLite在RecyclerView中动态添加按钮