CGIHTTPServer使ってデバッグする場合
コード無修正のままxrea上で実行可能。ただしMySQLdbとかは使えない。
.projectのあるフォルダに以下の内容のRun.pyを作っておいてRun DialogのMain Moduleに"${workspace_loc:project_name}/Run.py"と登録しておくとよい(なお、srcフォルダはcgi-binにリネームすること)
import os, BaseHTTPServer, CGIHTTPServer,SimpleHTTPServer class PyHTTPRequestHandler(CGIHTTPServer.CGIHTTPRequestHandler): def do_POST(self): if self.is_cgi(): CGIHTTPServer.CGIHTTPRequestHandler.do_POST(self) else: self.do_GET(); def is_python(self,path): head,tail=os.path.splitext(path) return tail.lower() in (".py", ".pyw",".cgi") #warning! os.chdir(os.path.abspath(os.path.dirname(os.path.realpath(__file__)))) CGIHTTPServer.CGIHTTPRequestHandler.cgi_directories = ['/cgi-bin'] BaseHTTPServer.HTTPServer( ('127.0.0.1', 8080), PyHTTPRequestHandler ).serve_forever()
この場合窓口URLは以下の通り
http://localhost:8080/cgi-bin/index.py
コードはこんな感じ
!/virtual/taos/bin/python #!-*- coding:utf-8 -*- import sys import site import os import re import codecs import cgi; import cgitb; cgitb.enable() import logging import datetime sys.stdout.write('Content-type: text/html; charset=UTF-8') sys.stdout.write('\r\n\r\n') sys.stdout.write(""" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> .... </html>""")