0
嗨我有一個Web應用程序的問題。它總是給一個形式。我的代碼是這樣的:驗證的Web應用程序代碼
import webapp2
form="""
<form method="post">
what is your birthday
<br>
<label>Month
<input name="text" name="month">
</label>
<label>Day
<input name="text" name="day">
</label>
<label>Year
<input name="text" name="year">
</label>
<br>
<br>
<input type="submit">
</form>
"""
months = ['January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December']
def valid_day(day):
if day and day.isdigit():
day = int(day)
if day < 32 and day > 0:
return day
def valid_month(month):
if(month):
month = month.capitalize()
if month in months:
return month
def valid_year(year):
if year and year.isdigit():
year = int(year)
if year < 2020 and year > 1880:
return year
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.out.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.response.out.write(form)
else:
self.response.out.write("Thanks! That's a totally valid day!")
app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
但即使我給了一個正確的輸入,它仍然會給出表格。任何人都可以幫助我嗎?我無法檢查這裏有什麼問題。
嗨,你的幫助真的坦克:動作,你應該在那個位置
例如處理表單。我通過谷歌appengine在我的localhost:8080上運行我的Web應用程序。這是我的整個代碼。 –
我是如此回答你的問題,還是你問我另一個問題? 很高興我能幫到你 – shifloni