1

Working through LPTHW exercise 51 and hit a wall. Trying to get some basic user input through a browser and then display it. Code is as follows - first python:

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

Then the 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>

When I click "submit" the only thing I get back is "not found".

1
  • Your form action attribute says it's going to the /hello endpoint but I don't see it specified anywhere in your Python code Commented Jul 30, 2017 at 19:22

1 Answer 1

1

You have missed something important in your code in the Python file.

You should write this :

urls = (
   '/hello', 'Index'

instead of this :

urls = (
   '/', 'Index' ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.