Responding Based on Verification

Intro to Backend >> Forms and Inputs >> Responding Based on Verification

How and where to include the new functions we just made, into our file:

You will need to copy the list of months, the month function, the day function, and the year function, in that order, and paste them right after


and before class MainHandler(webapp2.RequestHandler): within

Here is what it should look like to run:

#!/usr/bin/env python
# Copyright 2007 Google Inc.
# Licensed under the Apache License, Version 2.0 (the “License”);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.
import webapp2


what is your birthday?


months = [‘January’,

month_abbs = dict((m[:3].lower(), m) for m in months)
def valid_month(month):
if month:
short_month = month[:3].lower()
return month_abbs.get(short_month)

def valid_day(day):
if day and day.isdigit():
day = int(day)
if day > 0 and day < 32: return day

def valid_year(year):
if year and year.isdigit():
year = int(year)
if year > 1900 and year < 2020:
return year

class MainHandler(webapp2.RequestHandler):
def get(self):

def post(self):
user_month = valid_month(self.request.get(‘month’))
user_day = valid_day(self.request.get(‘day’))
user_year = valid_year(self.request.get(‘year’))

if not (user_month and user_day and user_year):
self.response.out.write(“Thanks! That’s a totally valid day!”)

app= webapp2.WSGIApplication([(‘/’, MainHandler)], debug=True)

Author: ajoannaproject

Studying Udacity's Full Stack Web Developer program and passing on my improvements, hints, hacks, and updates to other students via

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s