【问题标题】:"405 Method Not Allowed" in Python webapp2Python webapp2中的“405方法不允许”
【发布时间】:2017-04-13 11:30:54
【问题描述】:
import webapp2

form="""
     <form method="post">
          <input type="" name="day">
          <input type="" name="month">
          <input type="" name="year">
          <input type="submit" name="">
     </form>
     """
class MainPage(webapp2.RequestHandler):

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

def post(self):
    self.response.out.write("thank")

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

此代码响应

405 方法不允许

此资源不允许使用 POST 方法。

【问题讨论】:

  • 欢迎来到 Stack Overflow。请edit您的问题并修复已发布代码的缩进,以便我们可以查看class 的一部分和不是。

标签: python webapp2


【解决方案1】:

我遇到了同样的问题。您使用的编辑器的“缩进”配置错误,这对于 python 的解释器正确解释代码至关重要。

尝试用 Python IDE 重写这个程序。

【讨论】:

    【解决方案2】:

    这与您的配置有关。我测试了您的代码几乎与您发布的代码相同,并且它响应正确(使用 google appengine)。

    class MainPage(webapp2.RequestHandler):
        form = """
             <form method="post">
                  <input type="" name="day">
                  <input type="" name="month">
                  <input type="" name="year">
                  <input type="submit" name="">
             </form>
             """
        def get(self):
            self.response.out.write(self.form)
    
        def post(self):
            self.response.out.write("thank")
    
    
    app = microwsgi.MicroWSGIApplication([
                                          ('/MainPage', MainPage)...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 2021-09-17
      • 2021-12-20
      • 2020-09-15
      • 2023-03-23
      • 2011-04-05
      相关资源
      最近更新 更多