0

I just installed Google app engine for Python 2.7 and I wrote some code for test. Just a simple HTML form. 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. I really don't know why it's not working.

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

Later Edit: I solved this by simply writing the "write_form" procedure after the "get" procedure inside the MainPage class.

Xyntell
  • 155
  • 1
  • 14

1 Answers1

1

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

Community
  • 1
  • 1
matt3o
  • 615
  • 1
  • 5
  • 17