网页不重新加载

时间:2013-10-16 16:13:14

标签: python html webpage

我正在执行以下代码。

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 页面时,我什么都没看到。页面是空的。

1 个答案:

答案 0 :(得分:0)

我不熟悉webapp2,但是:

快速查看tutorials后,我看到他们写道:

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

你的代码没有正确缩进,你应该:

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

字符串“form”似乎不是一个有效的html页面

也许你可以试试

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