2010年12月19日日曜日

Google App Engine+Pythonで問い合わせフォーム作成(その後)

さて、Pythonで問い合わせフォーム作成ですが、師匠のアドバイスを受け、問い合わせフォーム画面と確認フォーム画面の遷移をGoogle App Engineのデータストアに保存することなく、コードをシンプル化することまでできました。


コードは以下の通り。
 'template/contact.html'と 'template/confirm.html'はFrontPageで作成しました。



# -*- coding:utf-8 -*-


import cgi
import wsgiref.handlers
import os
from google.appengine.ext.webapp import template
from google.appengine.ext import webapp


class ContactForm(webapp.RequestHandler):
  def get(self):
    template_values ={}


    path = os.path.join(os.path.dirname(__file__), 'template/contact.html')
    self.response.out.write(template.render(path, template_values))


class ConfirmForm(webapp.RequestHandler):
  def get(self):

    template_values = {
       'company' : self.request.get('company'),
       'division' : self.request.get('division'),
       'yourname' : self.request.get('yourname'),
       'furigana' : self.request.get('furigana'),
       'mailaddress' : self.request.get('mailaddress'),
       'tel' : self.request.get('tel'),
       'R1' : self.request.get('R1'),
       'content' : self.request.get('content'),
       'agree' : self.request.get('agree') ,
      }


    path = os.path.join(os.path.dirname(__file__), 'template/confirm.html')
    self.response.out.write(template.render(path, template_values))


def main():
    application = webapp.WSGIApplication(
                                     [('/', ContactForm),
                                      ('/confirm', ConfirmForm),
                                      ],
                                     debug=True)
    wsgiref.handlers.CGIHandler().run(application)


if __name__ == "__main__":
  main()


今、確認フォームの「送信」ボタンで、スプレッドシートに書き込む機能を追加しようとしていますが、gdataのモジュールがうまく認識されなくて、またまた苦戦してます。Googleのヘルプは英語が多いということもありよくわからないし・・・
うまくいったらまたブログにアップします。





1 件のコメント:

  1. html側のソースを読んでいないので、断定できないのですが、XSSの攻撃を合う可能性ありです。

    返信削除