Handling Web Forms Google App Engine
If we want users to be able to post their own greetings, we need a way to process information submitted by the user with a web form. The webapp framework makes processing form data easy.
1 2 3 4 5 6 7 8 9 10 11 | class MainPage(webapp.RequestHandler): def get(self): self.response.out.write(""" <html> <body> <form action="/sign" method="post"> <div><textarea name="content" rows="3" cols="60"></textarea></div> <div><input type="submit" value="Sign Guestbook"></div> </form> </body> </html>""") |
Now lets pull the data out of the post…
1 2 3 4 5 | class Guestbook(webapp.RequestHandler): def post(self): self.response.out.write('<html><body>You wrote:<em>') self.response.out.write(cgi.escape(self.request.get('content'))) self.response.out.write('</em></body></html>') |
By using self.request.get(‘content’) i can get the post data from the field “content”. Easy right?
Basics of Google App Engine
Developing a Google App using the App engine is quick and easy! If you have a background in python then its even easier! For most of us that don’t have a lot of python in our background it becomes a little more challenging.
Our first step is to get the foundation of python so we can work with the Google frameworks. So like most frameworks or code, we have a config/application file. This file is used to direct routes for URL’s to access many files in your application and to define a version and runtime.
app.yaml
1 2 3 4 5 6 7 8 | application: helloworld version: 1 runtime: python api_version: 1 handlers: - url: /.* script: helloworld.py |
Now lets create the “helloworld.py” file.
1 2 3 | print 'Content-Type: text/plain' print '' print 'Hello, world!' |
Very similar to php using print.
Now that you have the basic files to run an application you can now start the app by clicking run on the Google app engine tool. Visit the app via “http://localhost:8080″. You should now see “Hello, world!”
I will be covering more python and Google App Engine in the coming weeks. Thanks for reading.
Categories
Pages
- contact
- Contact Form V1.8
- FlickrHelper
- Guestbook V1.01 ASP
- Guestbook V2.4.7
- iFrame Loader
- Scriptatype:PHP
- Winn Cal
- Winn Tracker
