当前位置: 动力学知识库 > 问答 > 编程问答 >

python - simple hello world program gives issue in webpy

问题描述:

I am trying to use the webpy server and it works for the hello world if I try the same with the template it gives me this issue.

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!

Error

<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/

why am I getting this issue?

网友答案:

You must reorder your template file. The $def statement must come first:

$def with (name)
<em>Hello</em>, world!
分享给朋友:
您可能感兴趣的文章:
随机阅读: