首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Python应用程序错误(Udacity)

Python应用程序错误(Udacity)
EN

Stack Overflow用户
提问于 2015-08-12 15:32:42
回答 3查看 194关注 0票数 1

我一直在使用udacity.com学习编程一个应用程序,它允许你输入你的年龄,当你点击提交它检查你是否输入了正确的年、月和日。每次我点击提交并在谷歌应用引擎上运行它时,本地主机网页就会变黑。在我的代码中我遗漏了什么地方。我检查了我的代码,它看起来应该可以工作。我需要另一双眼睛盯着这个。

代码语言:javascript
复制
    import webapp2

form="""  
<form method="post">
    What is your birthday?
    <br>
    <label>Month<input type="type" name="month"></label>
    <label>Day<input type="type" name="day"></label>
    <label>Year<input type="type" name="year"></label>
    <div style="color: red">%(error)s</div>
    <br>
    <br>
    <input type="submit">
</form> 
"""
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)
EN

Stack Overflow用户

发布于 2015-08-19 05:29:15

我逐字逐句地尝试了你的代码,我得到了下面的错误,它导致了空白屏幕。

代码语言:javascript
复制
ERROR    2015-08-18 21:27:32,377 wsgi.py:263]
Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/Users/Josh/main.py", line 1
    import webapp2
   ^
IndentationError: unexpected indent

在python中,空格很重要。您的初始import webapp2month_abbvs = dict((m[:3].lower(),m) for m in months)似乎有一些不一致的缩进。

票数 0
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31958785

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档