当我访问localhost:9080时,我所得到的只是一个空白页面 [英] All I get is a blank page when I visit localhost:9080

查看:204
本文介绍了当我访问localhost:9080时,我所得到的只是一个空白页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用udacity.com来学习编程,但遇到了一些与我的代码(python)有关的问题。该应用程序的帖子允许放下你出生的那一天,当你推送提交它的帖子说谢谢你是一个完全有效的一天!。它没有这样做。应用程序只是重新启动。有人可以告诉我为什么is语句不起作用以及如何解决它。

I have been using udacity.com to learn to program but I ran into some problem with my code(python). The application is post to allow to put down the day you were born and when you push submit it's post to say "Thanks That's a totally valid day!". It's not doing it. The application just restarts again. Can some tell me why the is statement is not working and how to fix it.

import webapp2
form="""

    <form>
        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>

"""
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_month 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)


推荐答案

该片段有语法错误,如果您正在观看终端/控制台,您会注意到Python抱怨 else (它缺少一个尾随的)。观察控制台并理解它的含义,

That fragment has a syntax error. If you're watching the terminal/console, you'll notice Python complain about the else (which is missing a trailing :). Watching the console, and understanding what it's saying, is key if you want to make progress.

修正后,您会看到表单,然后当您尝试发布时,您会得到一个405方法不允许,因为 post 方法是过度缩进的。

With that fixed, you'll see the form. Then, when you trying posting, you'll get a "405 Method not allowed" because the post method is over-indented.

这篇关于当我访问localhost:9080时,我所得到的只是一个空白页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆