Google应用引擎HTTP错误500

时间:2016-08-29 12:07:52

标签: python google-app-engine

我刚安装了适用于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)中看到此消息:&#34; IndentationError:unindent与任何外部缩进级别都不匹配 INFO 2016-08-29 12:17:37,155 module.py:788]默认值:&#34; GET / HTTP / 1.1&#34; 500 - &#34;

后来的编辑:我只是简单地写了#34; write_form&#34; &#34; get&#34;之后的程序MainPage类中的过程。

1 个答案:

答案 0 :(得分:1)

你可能混淆了标签和空格。有关如何解决此问题的详细信息和提示,请参阅此答案:https://stackoverflow.com/a/3920674/3771575

相关问题