So I’m getting into the process of putting some of my first python code online and I’m a little fuzzy about some things. When we assign app to web.application(urls, globals()), what is going on exactly? Also, the line form = web.input(name="Nobody", greet=None) is referring to the two input forms in my other script called hello_form, but what is its purpose here? We’re calling form.greet and form.name on the next line I see, but those should be variables created based on user input, (yet we say name = "Nobody"?).
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=None)
greeting = "%s, %s" % (form.greet, form.name)
return render.index(greeting = greeting)
if __name__ == "__main__":
app.run()
creates a variable named
appand stores the result of callingweb.application()in it. In other words, you create a web application object, and store that object inapp.The values specified for
nameandgreethere are the default values – namely, those used if no user specified values are provided in the request.