2016-12-03 84 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