在使用googleappengine时,如何将表单数据编码到url?在
下面的代码生成一个表单,您可以在其中输入一些文本。然后文本显示在另一页"/sign"
我想直接指向/sign
,而不是指向/sign?message="hello"
这是我的代码,从这里开始:https://developers.google.com/appengine/docs/python/gettingstartedpython27/handlingforms)
import cgi
import webapp2
from google.appengine.api import users
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.out.write("""
<html>
<body>
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
</body>
</html>""")
class Guestbook(webapp2.RequestHandler):
def post(self):
self.response.out.write('<html><body>You wrote:<pre>')
self.response.out.write(cgi.escape(self.request.get('content')))
self.response.out.write('</pre></body></html>')
app = webapp2.WSGIApplication([('/', MainPage),
('/sign', Guestbook)],
debug=True)
我不确定你到底想达到什么目的。如果你写下你的意图,你可能会得到更可靠的建议。在
为了得到结果,我想你的描述需要使用get而不是post。Get将更改url。以下是修改后的代码:
如果您想了解更多关于webapp2和get-and-post方法的信息,请查看udacity CS253
相关问题 更多 >
编程相关推荐