<p>代码正确,工作正常。您需要在其他地方查找405错误的解释。</p>
<p><strong>编辑</strong></p>
<p>你公布了你的实际代码了吗?单击“提交”时,下面的代码将为您提供405方法不允许的错误。它有一个微妙的错误。。。:)</p>
<pre><code>import webapp2
form= """
<html>
<head>
<title>Unit 2 Rot 13</title>
</head>
<body>
<h2>Enter some text to ROT13:</h2>
<form method="post" action="/rot13">
<textarea name="text"
style="height: 100px; width: 400px;"></textarea>
<br>
<input type="submit">
</form>
</body>
</html> """
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write(form)
class Rot13Handler(webapp2.RequestHandler):
# Error here: mistyped get instead of post :)
def get(self):
text = self.request.get("text")
self.response.out.write(text)
app = webapp2.WSGIApplication([('/', MainHandler),
('/rot13', Rot13Handler)],
debug=True)
</code></pre>
<p>如果您的路由输入不正确,也会发生同样的情况,如:</p>
<pre><code>app = webapp2.WSGIApplication([('/', MainHandler),
('/rot13', MainHandler)],
debug=True)
</code></pre>
<p><strong>编辑(谢谢,@Nick Johnson)</p>
<p>如果以上都不起作用,考虑从头开始,检查您的GAE设置。</p>
<ol>
<li>在<code>main.py</code>模块旁边是否有有效的<code>app.yaml</code>文件?</li>
<li>你能在标准的Google AppEngine安装中运行留言簿演示应用程序吗?</li>
<li>如果没有,则发布错误消息(如果有),以及运行该错误消息的系统的详细信息。</li>
<li>如果你能运行留言簿,你能试着通过编辑它来重建你的应用程序吗?我发现这在过去对我有效。</li>
</ol>