简体   繁体   English

Google App Engine HTTP错误500

[英]Google app engine HTTP error 500

I just installed Google app engine for Python 2.7 and I wrote some code for test. 我刚刚安装了适用于Python 2.7的Google应用程序引擎,并编写了一些测试代码。 Just a simple HTML form. 只是一个简单的HTML表单。 Here is the code: 这是代码:

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)

And then I tried to write a separate procedure that writes out my form, like so: 然后,我尝试编写一个单独的过程来写出我的表单,如下所示:

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)

Well, the thing is that the first code is working fine, but the second one is returning the HTTP error 500. I tried this out from a course on Udacity and I simply copied the code from there. 好吧,事实是,第一个代码运行正常,但是第二个代码返回HTTP错误500。我从Udacity上的课程中尝试了这一点,我只是从那里复制了代码。 I really don't know why it's not working. 我真的不知道为什么它不起作用。

PS. PS。 I see this message in terminal (Linux): "IndentationError: unindent does not match any outer indentation level INFO 2016-08-29 12:17:37,155 module.py:788] default: "GET / HTTP/1.1" 500 -" 我在终端(Linux)中看到此消息:“ IndentationError:unindent与任何外部缩进级别不匹配INFO 2016-08-29 12:17:37,155 module.py:788]默认:“ GET / HTTP / 1.1” 500-”

Later Edit: I solved this by simply writing the "write_form" procedure after the "get" procedure inside the MainPage class. 以后的编辑:我通过在MainPage类中的“ get”过程之后简单地编写“ write_form”过程来解决此问题。

You have probably mixed up tabs and spaces. 您可能混淆了制表符和空格。 See this answer for more information and hints on how to fix it: https://stackoverflow.com/a/3920674/3771575 请参阅此答案以获取更多信息和有关如何解决它的提示: https : //stackoverflow.com/a/3920674/3771575

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM