我一直在使用udacity.com网站学习编写一个应用程序,让你输入你的年龄,当你点击提交它检查你是否输入正确的年,月,日。每次我在googleappengine上推送并运行它时,本地主机的网页就会变成黑色。在我的代码中我错过了什么地方。我检查我的代码,它看起来应该可以工作。我需要另一双眼睛。在import webapp2
form="""
What is your birthday?
Month
Day
Year
"""
def valid_year(year):
if year and year.isdigit():
year = int(year)
if year > 1900 and year < 2020:
return year
def valid_day(day):
if day and day.isdigit():
day = int(day)
if day > 0 and day <= 31:
return day
months = ['Janurary',
'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:
short_month = month[:3].lower()
return month_abbvs.get(short_month)
class MainPage(webapp2.RequestHandler):
def write_form(self, error=""):
self.response.out.write(form % {"error": error})
def get(self):
self.write_form()
self.valid_year(year)
self.valid_day(day)
self.valid_month(month)
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.write_form("That doesn't look valid to me, friend.")
else:
self.response.out.write("Thanks! That's a totally valid day!")
app = webapp2.WSGIApplication([('/',MainPage)], debug=True)