gpt4 book ai didi

python - 简单的 hello world 程序在 webpy 中出现问题

转载 作者:行者123 更新时间:2023-12-01 05:55:10 27 4
gpt4 key购买 nike

我正在尝试使用 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/

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

最佳答案

您必须重新排序模板文件。 $def 语句必须放在前面:

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

关于python - 简单的 hello world 程序在 webpy 中出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12948381/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com