【问题标题】:Web Page Not Reloading网页未重新加载
【发布时间】:2013-10-17 03:48:21
【问题描述】:

我正在执行以下代码。

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

【问题讨论】:

  • 什么是网页服务? This page 建议 Google App 引擎或本地设置应该这样做。您是否设置了其中任何一个?

标签: python html webpage


【解决方案1】:

我不熟悉 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    相关资源
    最近更新 更多