After you have created an instance of the web server, start the web server by calling its serve_forever() function. : Web Server « Network « Python Tutorial






import os, sys
import BaseHTTPServer, cgi

servAddr = ('',8080)

#Define the HTTP handler that overrides do_GET
class httpServHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_GET(self):
        if self.path.find('?') != -1:
            self.path, self.query_string = self.path.split('?', 1)
        else:
            self.query_string = ''
        self.send_response(200)
        self.send_header('Content-type','text/html')
        self.end_headers()

#Setup Global Environment
        self.globals = dict(cgi.parse_qsl(self.query_string))
#Redirect output to browser
        sys.stdout = self.wfile

#Execute the script remotely
        self.wfile.write("<h2>Handle Get</h2><P>")
        self.wfile.write("<LI>Executing <b>%s</b>" % (self.path))
        self.wfile.write( "<li>With Globals<B>%s</b><hr>" % (self.globals))
        execfile(self.path, self.globals)

os.chdir('/myTest')

serv = BaseHTTPServer.HTTPServer(servAddr, httpServHandler)

serv.serve_forever()








21.22.Web Server
21.22.1.Creating an HTTP Server to Handle GET Requests
21.22.2.After you have created an instance of the web server, start the web server by calling its serve_forever() function.
21.22.3.Once you have created an instance of the web server, start the web server by calling its serve_forever() function.
21.22.4.Creating an HTTP Server to Process CGI Scripts
21.22.5.Simple Web Server
21.22.6.Basic HTTP Server Example
21.22.7.Basic HTTP CGI Server Example with forking
21.22.8.Basic HTTP Server Example with threading