我一直在关注the tutorial on the web.py website,我正在努力让html页面正常运行,但我不断收到此错误:
<type 'exceptions.SyntaxError'> at /
invalid syntax Template traceback:
File 'templates\\index.html', line 14 </body> (index.html, line 14)
我无法弄清楚我做错了什么(因为我基本上只是复制/粘贴教程)。
以下是 index.html 的内容:
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
$def with (name)
$if name:
I just wanted to say <em>hello</em> to $name.
$else:
<em>Hello</em>, world!
</body>
</html>
这是 code.py :
import web
render = web.template.render('templates/')
urls = (
'/', 'index'
)
class index:
def GET(self):
name = 'Bob'
return render.index(name)
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
为什么说</body>
有语法错误?结构与web.py有什么不同吗?
答案 0 :(得分:0)
尽量不要在模板中使用html,head和body标签。 所以你的代码看起来像这样:
$def with (name)
$if name:
I just wanted to say <em>hello</em> to $name.
$else:
<em>Hello</em>, world!