2016-12-03 3 views
0

Zed ShawのLearn Python The Hard Way tut#50に続いて、初めてweb.pyを使いこなしています。 複数のWebページを設定しようとしていますが、索引/は働く。 私は他のすべてをテストして、それはすべて動作します。私はweb.pyのURL処理

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

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

を交換するときそれは私のfooのウェブページ

をロードしますが、私は

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

) 

を試してみてはlocalhost/fooの入力したときに:私のブラウザに8080を私が取得しますエラー接続が拒否されました 私のコード変更の間にサーバーを再起動しましたjus確かめるために何も変わらない。

私は複数の例を試してみましたが、料理の例を無駄にしましたが、これは私を困惑させました。 私が見逃していることを私に見せてください。

コードfoo.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> 

index.htmlを

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() 

app.py

以下

$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