Pyramid默认使用Chameleon ZPT模板,从pylons转过来的比较习惯mako模板。

在Pyramid如何更改模板引擎呢?

 

1. 在配置文件development.ini中,添加上:

mako.directories = [project name]:[root path]

project name是你项目的名称

root path 是你模板文件存放的根目录

跟多关于mako的设置: mako-template-render-settings

 

 

2. 修改项目的__init__.py文件,在main函数中添加上:

config.add_renderer('.html', 'pyramid.mako_templating.renderer_factory')

凡是使用.html结尾的模板,都会使用mako引擎

 

3. 当在View.py中,使用.html的模板,就会使用mako模板引擎了。

return render_to_response('/admin/login.html', {}, request = request)

相关文章:

  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2021-05-26
  • 2022-12-23
  • 2021-10-08
  • 2022-12-23
  • 2021-09-14
猜你喜欢
  • 2021-12-04
  • 2022-02-11
  • 2021-06-05
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
相关资源
相似解决方案