Web Development


Using google app engine create small web application which can take birthday as input, validate the input and redirect to the ‘thanks’ page.

To use google app engine: https://drive.google.com/file/d/0Byu3UemwRffDc21qd3duLW9LMm8/view

import webapp2

 <select name='q'>
 <option value='1'>the mumber one<option>
 <input type='submit'>
<form method='post'>
 What is your birthday?
 <label> Month
 <input type='text' name='month' value='%(month)s'>

<label> Day
 <input type='text' name='day' value='%(day)s'>

<label> Year
 <input type='text' name='year' value='%(year)s'>

<br> <br> <input type='submit'> </form> """ months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] month_abbvs = dict((m[:3].lower(),m) for m in months) def valid_month(month): if month: month = month[:3].lower() return month_abbvs.get(month) def valid_day(day): if day and day.isdigit(): day = int(day) if day > 0 and day <= 31: return day def valid_year(year): if year and year.isdigit(): year = int(year) if year > 1900 and year < 2020: return year def escape_html(s): for (i, o) in (("&", "&amp;"), (">", "&gt;"), ('<', "&lt;"), ('"', "&quote;")): s = s.replace(i, o) return s import cgi def escape_html1(s): return cgi.escape(s, quote=True) given_string = "I think %s is a perfectly normal thing to do in public." def sub1(s): return given_string % s given_string2 = "I think %s and %s are perfectly normal things to do in public." def sub2(s1, s2): return given_string2 %(s1, s2) class MainHandler(webapp2.RequestHandler): def write_form(self, error="", month='', day='', year=''): self.response.write(form % {'error':error, 'month':escape_html1(month), 'day':escape_html1(day), 'year': escape_html1(year)}) def get(self): #self.response.headers['Content-Type'] = 'text/plain' self.write_form() def post(self): user_month = self.request.get('month') user_day = self.request.get('day') user_year = self.request.get('year') month = valid_month(user_month) day = valid_day(user_day) year = valid_year(user_year) if not (month and day and year): self.write_form("That doesn't look good to me", user_month, user_day, user_year) else: self.redirect('/thanks') class ThanksHandler(webapp2.RequestHandler): def get(self): self.response.write("Thanks! Thats totally vaid day !") app = webapp2.WSGIApplication([('/', MainHandler), ('/thanks', ThanksHandler)], debug=True)