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.
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
The app.yaml file is pretty much unchanged, except for the application name:
ae-08-loginversion: 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 ...