在Python中的Google应用程序引擎中获取表单提交后的显示
表单发布后不显示页面内容,但在直接查看页面时显示。我有一段Python应用程序引擎代码,它试图指向一个新页面并显示一段编程定义的文本(即在代码中,而不是在html中)。但是,按下表单的提交按钮,我会看到一个空白页,没有错误消息 我一直在使用谷歌应用程序引擎代码示例。这个表单只是选择了一些选项,但我甚至没有从中收集任何东西,应该转到新页面,但是它没有,我无法找出哪里可能出错 我有在Python中的Google应用程序引擎中获取表单提交后的显示,python,google-app-engine,Python,Google App Engine,表单发布后不显示页面内容,但在直接查看页面时显示。我有一段Python应用程序引擎代码,它试图指向一个新页面并显示一段编程定义的文本(即在代码中,而不是在html中)。但是,按下表单的提交按钮,我会看到一个空白页,没有错误消息 我一直在使用谷歌应用程序引擎代码示例。这个表单只是选择了一些选项,但我甚至没有从中收集任何东西,应该转到新页面,但是它没有,我无法找出哪里可能出错 我有 class MainPage(webapp.RequestHandler): def get(self):
class MainPage(webapp.RequestHandler):
def get(self):
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
及
在HTML中:index.HTML
<html>
<body>
<form action="/confirm" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Submit"></div>
</form>
</body>
</html>
我想知道为什么如果我提交表格,我没有得到你确认的答案!消息,但如果我去/确认我去了。谢谢。我想测试一下您的断言,即使用curl来发布一些东西,POST-to-Confirm可以正确工作: curl-v0-F content=blah-F submit=submit'http://my-app.appspot.com/confirm" 如果工作正常,那么我将使用HttpFox(FF扩展)查看发送到服务器的内容
似乎你要么没有提交你认为你是什么,要么你的后处理程序没有按你认为的那样工作。以上两个步骤都有助于澄清哪一个是哪一个。我将测试您的断言,即使用curl-to-POST可以正确地使用POST-to-Confirm: curl-v0-F content=blah-F submit=submit'http://my-app.appspot.com/confirm" 如果工作正常,那么我将使用HttpFox(FF扩展)查看发送到服务器的内容
似乎你要么没有提交你认为你是什么,要么你的后处理程序没有按你认为的那样工作。以上两个步骤都有助于澄清哪一个是哪一个。您的代码运行得非常顺利;对于某些奇怪的缩进错误(这可以解释405错误),您可能没有正确实现
post
方法
复制并粘贴我的应用程序.py
,然后重试:
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler):
def get(self):
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, {}))
class Confirm(webapp.RequestHandler):
def post(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('You have confirmed!')
application = webapp.WSGIApplication(
[('/', MainPage),
('/confirm', Confirm)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
你的代码运行得很顺利;对于某些奇怪的缩进错误(这可以解释405错误),您可能没有正确实现
post
方法
复制并粘贴我的应用程序.py
,然后重试:
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler):
def get(self):
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, {}))
class Confirm(webapp.RequestHandler):
def post(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('You have confirmed!')
application = webapp.WSGIApplication(
[('/', MainPage),
('/confirm', Confirm)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
@Rusty我认为您应该更改表单提交方法以获取或发布,并确保在application.py中也编写了相同的表单。或者你可以这样做
class Confirm(webapp.RequestHandler):
def post(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('You have confirmed!')
def get(self):
return Confirm.post(self)
@Rusty我认为您应该更改表单提交方法以获取或发布,并确保在application.py中也编写了相同的表单。或者你可以这样做
class Confirm(webapp.RequestHandler):
def post(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('You have confirmed!')
def get(self):
return Confirm.post(self)
您的主页处理程序似乎存在缩进问题。这是在这里编辑时缩进的问题还是你有缩进的问题?缩进问题就在S.O上。修复了你的缩进问题你的主页处理程序似乎有缩进问题。这是在这里编辑时缩进的问题还是你有这样的问题?缩进问题就在S.O上。修复了缩进问题。在命令行上查看dev_服务器的输出时,每当提交页面时,我都会收到405个错误。这可能是权限问题吗?HTTP 1.0,假设正文后关闭
GET()
,而不是POST())
。在命令行上查看dev_服务器的输出,每当提交页面时,都会出现405错误。这可能是权限问题吗?HTTP 1.0,假设正文后关闭GET()
,而不是POST()
。