I have been using google app engine for a udacity class. I been trying to get some code to work but when I showed the website my python code they said nothing was wrong with it. They said I should look and fix or
import webapp2
from cgi import escape
html = """
<form method="post">
What is your birthday?
<br>
<label>Month: <input type="text" name="m" value="%(input_month)s"></label>
<label>Day: <input type="text" name="d" value=%(input_day)s></label>
<label>Year: <input type="text" name="y" value=%(input_year)s></label>
<div style="color: red">%(error_msg)s</div>
<br><br>
<input type="submit">
</form>
"""
class RootPageHandler(webapp2.RequestHandler):
months = [
'January', 'February', 'March', 'April', 'May', 'June', 'July'
'August', 'September', 'October', 'November', 'December'
]
months_abbr = dict((month[:3].lower(), month) for month in months)
def valid_month(self, user_input = None):
if type(user_input) == unicode:
test_value = user_input[:3].lower()
if test_value in self.months_abbr:
return self.months_abbr[test_value]
return ''
def valid_day(self, user_input = None):
if type(user_input) == unicode and user_input.isdigit():
number = int(user_input)
if (number > 0 and number < 32):
return user_input
return ''
def valid_year(self, user_input = None):
if type(user_input) == unicode and user_input.isdigit():
number = int(user_input)
if (number >= 1900 and number <= 2020):
return user_input
return ''
def write_html(self, error = '', month = '', day = '', year = ''):
self.response.out.write(html % {
'error_msg': error,
'input_month': escape(month, quote = True),
'input_day': escape(day, quote = True),
'input_year': escape(year, quote = True)
})
def get(self):
self.write_html()
def post(self):
month_input = self.request.get('m')
day_input = self.request.get('d')
year_input = self.request.get('y')
month_valid = self.valid_month(month_input)
day_valid = self.valid_day(day_input)
year_valid = self.valid_year(year_input)
if not (month_valid and day_valid and year_valid):
self.write_html(error = "That doesn't look like a valid birthday",
month = month_valid, day = day_valid, year = year_valid)
else:
self.redirect('/thanks')
class ThanksPageHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write('validated')
webapp = webapp2.WSGIApplication([
('/', RootPageHandler),
('/thanks', ThanksPageHandler)
], debug=True)