我一直在这个上拉头发30分钟,我不知道我做错了什么,因为没有语法错误但是post方法在它应该写出消息时继续重新发送表单else
声明
main.py
import webapp2
import dateValidation
form = """
<form>
<input type="text name="month">
<input type="text name="day">
<input type="text name="year">
<input type="submit">
</form>>
"""
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.out.write(form)
def post(self):
user_month=dateValidation.valid_month(self.request.get('month'))
user_day=dateValidation.valid_day(self.request.get('day'))
user_year=dateValidation.valid_year(self.request.get('year'))
if not (user_month and user_day and user_year):
self.response.out.write(form)
else:
self.response.out.write("Thanks, that's a totally valid day!")
app = webapp2.WSGIApplication([('/', MainPage)],
debug=True)
dateValidation.py:
months = ['January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December']
def valid_month(month):
if month:
cap_Month=month.capitalize()
if cap_month in months:
return cap_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>1920 and year<2020:
return year