| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

Google App Engine Http Formパラメータの取得

提供: MyMemoWiki
ナビゲーションに移動 検索に移動

Google App Engine Http Formパラメータの取得

Http Form パラメータの処理。 以下参照。

  • POSTメッセージハンドラ
  • HTML特殊文字のエスケープ
  • FORMパラメータ取得
import cgi
import wsgiref.handlers

from google.appengine.api import users
from google.appengine.ext import webapp

class MainPage(webapp.RequestHandler):
    def get(self):
        self.response.out.write("""
        <html>
          <body>
            <form action="/msg" method="post">  
              name:<input type="text" name="name" value=""><br>
              msg :<textarea name="message"></textarea><br>
              <input type="submit">
            </form>
          </body>
        </html>
        """)

class MessagePage(webapp.RequestHandler):
    def post(self): # POSTメッセージハンドラ
        self.response.out.write('<html><body>')
        self.response.out.write('name:' 
                                + cgi.escape( # HTML特殊文字のエスケープ
                                  self.request.get('name')) # FORMパラメータ取得
                                + '<br>')
        self.response.out.write('message:<pre>' 
                                + cgi.escape(
                                  self.request.get('message')) 
                                + "</pre>")
        self.response.out.write('</body></html>')
        
def main():
    application = webapp.WSGIApplication(
                                         [('/', MainPage),
                                          ('/msg', MessagePage)],
                                          debug=True 
                                         )
    wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
    main()