2017-07-30 5 views
0

LPTHWエクササイズ51で作業し、壁に当たってください。基本的なユーザー入力をブラウザから取得して表示しようとしています。次のようにコードがある - 最初のpython:ブラウザからの入力を取得する - python + forms

import web 

urls = (
    '/', 'Index' 
) 

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

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

    class Index(object): 
     def GET(self): 
      return render.hello_form() 

     def POST(self): 
      form = web.input(name="Nobody", greet="Hello") 
      greeting = "%s, %s" % (form.greet, form.name) 
      return render.index(greeting = greeting) 

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

次にHTML:

<html> 
    <head> 
     <title>Sample web form</title> 
    </head> 
<body> 

<h1>Fill out this form</h1> 

<form action="/hello" method="POST"> 
    A Greeting: <input type="text" name="greet"> 
    <br/> 
    Your Name: <input type="text" name="name"> 
    <br/> 
    <input type="submit"> 
</form> 

</body> 
</html> 

私は取り戻す唯一のことは、「見つからない」されて「送信」をクリックします。

+0

あなたのフォームを 'action'属性は、'/hello'エンドポイントになるだろうが、私はそれが指定され表示されていないと言いますあなたのPythonコードのどこにでも – Mangohero1

答えて

0

Pythonファイルのコードで重要なことを見逃しました。

urls = (
    '/hello', 'Index' 

の代わりに、この:

あなたはこの書くべき

urls = (
    '/', 'Index' ... 
関連する問題