【问题标题】:Google app engine HTTP error 500谷歌应用引擎 HTTP 错误 500
【发布时间】:2016-08-29 12:07:51
【问题描述】:

我刚刚为 Python 2.7 安装了 Google 应用引擎,并编写了一些代码进行测试。只是一个简单的 HTML 表单。代码如下:

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>

    <br>
    <br>
    <input type="submit">
</form>
"""

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.out.write(form)

    def post(self):
        self.response.out.write("Succes!")

app = webapp2.WSGIApplication([
     ('/', MainPage),
], debug=True)

然后我尝试编写一个单独的程序来写出我的表单,如下所示:

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>

    <br>
    <br>
    <input type="submit">
</form>
"""

class MainPage(webapp2.RequestHandler):
    def write_form(self):
        self.response.out.write(form)

    def get(self):
        self.write_form()

    def post(self):
        self.response.out.write("Succes!")

app = webapp2.WSGIApplication([
     ('/', MainPage),
], debug=True)

嗯,问题是第一个代码工作正常,但第二个代码返回 HTTP 错误 500。我从 Udacity 的课程中​​尝试过这个,我只是从那里复制代码。我真的不知道为什么它不起作用。

PS。我在终端(Linux)中看到这条消息:“IndentationError: unindent does not match any external indentation level INFO 2016-08-29 12:17:37,155 module.py:788] 默认值:"GET / HTTP/1.1" 500 -"

稍后编辑:我通过在 MainPage 类中的“get”过程之后简单地编写“write_form”过程来解决这个问题。

【问题讨论】:

    标签: python google-app-engine


    【解决方案1】:

    您可能混淆了制表符和空格。有关如何修复它的更多信息和提示,请参阅此答案:https://stackoverflow.com/a/3920674/3771575

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-28
      • 1970-01-01
      • 2013-05-17
      相关资源
      最近更新 更多