O'Reilly logo

Using Google App Engine by Charles Severance

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extending Our Application

Now that you understand how to handle templates in general, we can start to build a real application. Our first improvement will be to add a simple screen to prompt for the user’s account and password, as shown in Figure 6-12.

Login screen

Figure 6-12. Login screen

For now, as we don’t really have any user accounts, we will just pretend that all passwords are the word secret.

So far with this application, we have mostly been making HTTP GET requests as we navigate from one page to another. Now we will be handling POST requests as well. In a sense, this screen is somewhat like the number-guessing game—but instead, it’s a password-guessing game.

We will make it so that our login page is at the URL /login—we will be able to do a GET to the /login URL to get the account/password form, and we can do a POST to this URL to submit the account and password for checking.

Because this login activity is a whole new chunk of work, we will make a new handler called LoginHandler and route the /login URL to the LoginHandler.

The app.yaml file is pretty much unchanged, except for the application name:

application: ae-08-login
version: 1
runtime: python
api_version: 1
handlers:
- url: /static
  static_dir: static

- url: /.*
  script: index.py

We make several improvements to our index.py file:

import os import logging import wsgiref.handlers from google.appengine.ext import webapp from google.appengine.ext.webapp ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required