2016-12-03 83 views
0

我正在乱搞web.py第一次,遵循Zed Shaw的学习Python的艰难之路tut#50. 我试图设置多个网页,但似乎只能看到索引/工作。 我已经测试了其他一切,它都可以正常工作。当我更换在web.py中的网址处理

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> 

回答

0
删除

'FOO' 表达后逗号

urls = (
'/', 'Index', 
'/foo', 'FOO' 
) 

和运行

localhost:8080/foo 
+0

阿OK容易解决,THX –

+1

逗号不是一个问题,但是,是的,你需要有端口号':8080'主机后,后不'/foo'路径。 – pbuck