1 / 10

CGI Programming with Python

CGI Programming with Python. Gouichi Iisaka The Company was called Cray Research Japan Co., Ltd. CGI のためのモジュール. CGI http lib HTMLgen Bobo、BoboPOS Document Template. http://www.python.org/download/Contributed.html#netweb. CGI のためのモジュール. J P ython: Java プラットホームで動作

inoke
Download Presentation

CGI Programming with Python

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CGI Programming with Python Gouichi Iisaka The Company was called Cray Research Japan Co., Ltd.

  2. CGIのためのモジュール • CGI • httplib • HTMLgen • Bobo、BoboPOS • Document Template http://www.python.org/download/Contributed.html#netweb

  3. CGIのためのモジュール • JPython: Javaプラットホームで動作 • SSL Extensionhttp://www.as.cmu.edu/~geek/python-ssl.html • mod_pyapachehttp://www.msg.com.mx/pyapache/ http://www.python.org/download/Contributed.html#netweb

  4. Grail • すべてPythonで記述されたWebブラウザJava の HotJava に相当 • Pythonコードをアプレットとして実行可能

  5. JPython • 100% Pure Java • Pythonコードをアプレットとして実行可能 • 既存のJavaクラスライブラリも利用可能 • Javaに比べて2~10倍の開発効率 • OpenSource • 対応ブラウザ: • SUN HotJava • Microsoft Internet Explore4.0 • Netscape Navigator 4.06 以上

  6. Jpythonサンプルコード from java import awt, applet class ButtonDemo(applet.Applet): def init(self): self.b1 = awt.Button('Disable middle button',actionPerformed=self.disable) self.b2 = awt.Button('Middle button') self.b3 = awt.Button('Enable middle button', enabled=0, actionPerformed=self.enable) self.add(self.b1) self.add(self.b2) self.add(self.b3) def enable(self, event): self.b1.enabled = self.b2.enabled = 1 self.b3.enabled = 0 def disable(self, event): self.b1.enabled = self.b2.enabled = 0 self.b3.enabled = 1

  7. Jpythonサンプルコード from java import awt, applet class CheckboxDemo(applet.Applet): def init(self): cb1 = awt.Checkbox('Checkbox 1') cb2 = awt.Checkbox('Checkbox 2') cb3 = awt.Checkbox('Checkbox 3', state=1) p1 = awt.Panel(layout=awt.FlowLayout()) p1.add(cb1) p1.add(cb2) p1.add(cb3) cbg = awt.CheckboxGroup() cb4 = awt.Checkbox('Checkbox 4', cbg, 0) cb5 = awt.Checkbox('Checkbox 5', cbg, 0) cb6 = awt.Checkbox('Checkbox 6', cbg, 0) p2 = awt.Panel(layout=awt.FlowLayout()) p2.add(cb4) p2.add(cb5) p2.add(cb6) self.setLayout(awt.GridLayout(0, 2)) self.add(p1) self.add(p2) self.validate()

  8. CGIモジュール form = cgi.FieldStorage() form_ok = 0 if form.has_key("name") and form.has_key("addr"): if form["name"].value != "" and form["addr"].value != "": form_ok = 1 if not form_ok: print "<H1>Error</H1>" print "Please fill in the name and addr fields.” return …他の手続き...

  9. CGIのデバッグ • try … except の前でtracebackをインポート • sys.stderr を sys.stdout に割り付ける • ヘッダとブランク行が出力されることを確認 • デバッグするコードを try … except で囲む • exceptの中で traceback.print_exc() を呼ぶ

  10. CGIのデバッグ import sys import traceback print ”Content-type: text/html” print sys.stderr = sys.stdout try: … デバッグしたいコード… except: print print ”<PRE>” traceback.print_exc()

More Related