それはタブ/スペースに関係していると確信していますが、100万ドルの質問はプログラムのどこにありますか?
import webapp2
form="""
<form method="post">
What is your birthday?
<br>
<label> Month
<input type="text" name="month">
</label>
<label> Day
<input type="text" name="day">
</label>
<label> Year
<input type="text" name="year">
</label>
<div style="color: red">%s(error)s</div>
<br>
<br>
<input type="submit">
</form>
"""
months = ['January', 'Febuary','March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
mapping = dict((m[:3].lower(), m) for m in months)
def valid_month(month):
if month:
s_month = month[:3].lower()
return mapping.get(s_month)
def valid_day(day):
if day and day.isdigit():
day = int(day)
if day in range(1, 32):
return day
def valid_year(year):
if year and year.isdigit():
int_year = int(year)
if int_year in range(1900,2021):
return year
class MainPage(webapp2.RequestHandler):
def write_form(self, error=""):
self.response.out.write(form % {"error": error})
def get(self):
self.write_form()
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's wasn't valid, friend!")
else:
self.response.write("Thanks! That's a totally valid day!")
app = webapp2.WSGIApplication([('/', MainPage)], debug=True)