Return to the previous form
I'm working through Learn Python The Hard Way, and I'm currently working on Exercise 51, which asks the student to add a back link in the templates / index.html file so we can continue filling out the form and see the results. My code looks like this:
/bin
app.py
/static
/templates
hello_form.html
index.html
/tests
app.py is written like this:
import web
urls = (
'/hello', 'Index'
)
app = web.application(urls, globals())
render = web.template.render('templates/', base="layout")
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()
index.html written like this:
$def with (greeting)
$if greeting:
I just wanted to say <em style="color: green; font-size: 2em;">$greeting</em>
$else:
<em>Hello</em>, world!
hello_form.html is written like this:
<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>
This link is a button on a form, isn't it? How do I add a handler for this button?
Thanks in advance for your help.
+3
source to share
4 answers
I added these few lines to index.html and it worked.
<form>
<input type="button" value="Back" onclick="history.back()">
</input>
</form>
See https://www.computerhope.com/issues/ch000317.htm for details
Hope it helps.
0
source to share