【发布时间】:2016-12-03 18:32:04
【问题描述】:
在 Zed Shaw 的 Learn Python The Hard Way tut# 50 之后,我第一次搞砸了 web.py。 我正在尝试设置多个网页,但似乎只能让 index / 工作。 我已经测试了其他所有内容,并且一切正常。当我更换
urls = (
'/', 'Index',
)
与
urls = (
'/', 'foo',
)
它会加载我的 foo 网页
但是当我尝试时
urls = (
'/', 'Index',
'/foo', 'FOO',
)
并在我的浏览器中输入 localhost/foo:8080 我收到错误连接被拒绝 我已经杀死了服务器,在我的代码更改之间重新启动它只是为了确保没有任何变化。
我尝试了多个示例并使用了食谱示例但无济于事,这个让我很难过。 请告诉我我错过了什么。
代码如下
app.py
import web
urls = (
'/', 'Index',
'/foo', 'FOO',
)
app = web.application(urls, globals())
render = web.template.render('templates/')
class Index(object):
def GET(self):
greeting = "Hello World"
return render.index(greeting = greeting)
class FOO(object):
def GET(self):
foo_greeting = "Hello foo"
return render.foo(foos_greeting = foo_greeting)
if __name__ == "__main__":
app.run()
index.html
$def with (greeting)
<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>
</html>
foo.html
$def with (foos_greeting)
<html>
<head>
<title>Gothons Of Planet FOO</title>
</head>
<body>
$if foos_greeting:
I just wanted to say <em style="color: green; font-size: 2em;">$foos_greeting</em>.
$else:
<em>Hello</em>, foo foo!
</body>
</html>
【问题讨论】: