Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
45 lines (31 sloc) 930 Bytes
layout title
Use Jinja2 template engine in webpy

Use Jinja2 template engine in webpy


如何在web.py中使用Jinja2 ( 模板引擎?


首先需要安装Jinja2和webpy(0.3), 然后使用下面的代码做测试:

import web
from web.contrib.template import render_jinja

urls = (
        '/(.*)', 'hello'

app = web.application(urls, globals())

render = render_jinja(
        'templates',   # 设置模板路径.
        encoding = 'utf-8', # 编码.

#       var=newvar,
#       var2=newvar2,

class hello:
    def GET(self, name):
        return render.hello(name=name)

if __name__ == "__main__":

模板文件: templates/hello.html

Hello, {{ name }}.
Jump to Line
Something went wrong with that request. Please try again.