1

我正在尝试使用 webpy 服务器,如果我尝试使用它给我这个问题的模板,它适用于 hello world。

import web
render = web.template.render('templates/')

urls = (
    '/', 'index'
)

class index:
    def GET(self):
        name ='example'
        return render.index(name)

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()

templates/index.html

<em>Hello</em>, world!
$def with (name)

$if name:
    I just wanted to say <em>hello</em> to $name.
$else:
    <em>Hello</em>, world!

错误

<type 'exceptions.SyntaxError'> at /
invalid syntax Template traceback: File 'templates/index.html', line 8 None (index.html, line 8)

Python  /usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/template.py in compile_template, line 911
Web GET http://0.0.0.0:8080/

为什么我会遇到这个问题?

4

1 回答 1

2

您必须重新排序您的模板文件。$def声明必须先出现:

$def with (name)
<em>Hello</em>, world!
于 2012-10-18T07:30:02.993 回答