This part of the Python Guestbook code walkthrough shows how to handle user input.
This page is part of a multi-page tutorial. To start from the beginning and see instructions for setting up, go to Creating a Guestbook.
Configuring the app to use webapp2
The Guestbook sample uses the webapp2 framework, which is included in the App Engine environment and the App Engine Python SDK. You don't need to bundle webapp2 with your application code to use it.
The app.yaml file specifies that the app uses the webapp2 framework:
A webapp2 application has two parts:
- One or more
RequestHandlerclasses that process requests and build responses. - A
WSGIApplicationinstance that routes incoming requests to handlers based on the URL.
The app.yaml file specifies the app object in guestbook.py as the
handler for all URLs:
Defining a handler for form submission
The app object in guestbook.py is a WSGIApplication that defines which
scripts handle requests for given URLs.
The debug=True parameter tells webapp2 to print
stack traces to the browser output if a handler encounters an error or raises
an uncaught exception. This option should be removed before deploying the final
version of your application, otherwise you will inadvertently expose the
internals of your application.
The Guestbook handler has a post() method instead of a
get() method. This is because the form displayed by MainPage uses the
HTTP POST method to submit the form data.
The post() method gets the form data from self.request.