0

我正在执行以下代码。

import webapp2

form="""
    <form method = "post">
    What is your birthday?
    <p>
    <label>
    Day
    <input type = "text" name = "day">
    Month
    <input type = "text" name = "month">
    Year
    <input type = "text" name = "year">
    </p>
    <input type = "submit">
    </form>
    """

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

    def post(self):
    self.response.out.write(form)


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

当我尝试打开页面localhost:8080时,我什么也没看到。页面是空的。

4

1 回答 1

0

I am not familiar with webapp2 but:

after a quick look to tutorials I have seen them write:

self.response.write(...) instead of self.response.out.write()

your code is not correctly indented, you should have:

   def get(self):
       self.response.write(form)

the string "form" does not seem like a valid html page

maybe you could try

<!DOCTYPE html>
<html>
<head>
<title>Whatever</title>
</head>
<body>
    <form method = "post">
    What is your birthday?
    <p>
    <label>
    Day
    <input type = "text" name = "day">
    Month
    <input type = "text" name = "month">
    Year
    <input type = "text" name = "year">
    </p>
    <input type = "submit">
    </form>
</body>
</html>
于 2013-10-16T19:48:21.153 回答