4

我正在使用 web.py 构建一个简单的 HTML 模板,但是每次尝试运行基本应用程序时系统都会抛出错误。我不确定如何诊断。完整的追溯如下。有人对诊断方法有想法吗?

有人在此链接上提出了类似的问题,但没有得到回答:web.py 中的继承?

我为我的文件模仿的来源:http: //learnpythonthehardway.org/book/ex50.html

文件:

<html>
    <head>
        <title>Gothons Of Planet Percal #25</title>
    </head>
<body>

$if greeting:
    I just wanted to say <em style="color: green; font-size: 2em;">$greeting</em>.
$else:
    <em>Hello</em>, world!

</body>

应用程序.py:

import web

urls = (
  '/', 'Index'
)

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

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

class Index(object):
    def GET(self):
        greeting = "Hello World"
        return render.index(greeting = greeting)

if __name__ == "__main__":
    app.run()

追溯

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/web/wsgiserver/__init__.py", line 1245, in     communicate
    req.respond()
  File "/Library/Python/2.7/site-packages/web/wsgiserver/__init__.py", line 775, in respond
self.server.gateway(self).respond()
  File "/Library/Python/2.7/site-packages/web/wsgiserver/__init__.py", line 2018, in respond
    response = self.req.server.wsgi_app(self.env, self.start_response)
  File "/Library/Python/2.7/site-packages/web/httpserver.py", line 268, in __call__
    return self.app(environ, xstart_response)
  File "/Library/Python/2.7/site-packages/web/httpserver.py", line 236, in __call__
    return self.app(environ, start_response)
  File "/Library/Python/2.7/site-packages/web/application.py", line 276, in wsgi
    result = self.handle_with_processors()
  File "/Library/Python/2.7/site-packages/web/application.py", line 246, in     handle_with_processors
    return process(self.processors)
  File "/Library/Python/2.7/site-packages/web/application.py", line 243, in process
    raise self.internalerror()
  File "/Library/Python/2.7/site-packages/web/application.py", line 467, in internalerror
    return debugerror.debugerror()
  File "/Library/Python/2.7/site-packages/web/debugerror.py", line 305, in debugerror
    return web._InternalError(djangoerror())
  File "/Library/Python/2.7/site-packages/web/debugerror.py", line 290, in djangoerror
    djangoerror_r = Template(djangoerror_t, filename=__file__, filter=websafe)
  File "/Library/Python/2.7/site-packages/web/template.py", line 844, in __init__
    code = self.compile_template(text, filename)
  File "/Library/Python/2.7/site-packages/web/template.py", line 922, in compile_template
    ast = compiler.parse(code)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/compiler/transformer.py", line 51, in parse
    return Transformer().parsesuite(buf)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/compiler/transformer.py", line 128, in parsesuite
    return self.transform(parser.suite(text))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/compiler/transformer.py", line 124, in transform
    return self.compile_node(tree)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/compiler/transformer.py", line 167, in compile_node
    raise WalkerError, ('unexpected node type', n)
WalkerError: ('unexpected node type', 339)
4

1 回答 1

0

首先你应该$def with(greeting)在你的html页面中添加。

.html 文件:

$def with(greeting) 
<html>
    ...
</html>
    ...

然后更改:
app.py:

...
return render.index(greeting)
...
于 2020-02-17T12:56:40.053 回答