from SimpleHTTPServer import SimpleHTTPRequestHandler import SocketServer httpd = SocketServer.TCPServer((‘’, 8000), SimpleHTTPRequestHandler) httpd.serve_forever()
CGI: Common Gateway Interface ◦ need to start a new process for every request not recommened ◦ cgi, cgitb module FastCGI, SCGI(a simpler FastCGI) ◦ uses preforked backgroundprocesses to handle requests by imbedding interpreters into the web server CGI
A standard interface between web server and web applications written in Python WSGI application will work on any gateway interfaces: CGI, FastCGI, SCGI, mod_python, or mod_wsgi mod_wsgi: a WSGI server in Apache web server (WCGI-compliant) ◦ embedded mode (integrated with Apache process) ◦ daemon mode which is FastCGI-like wsgiref module ◦ A reference implementation of WSGI specification ◦ contains a small web server that can be used for testing
#!/usr/bin/env python from wsgiref.simple_server import make_server def application(environ, start_response): response_body = 'Hello, world!' status = '200 OK' response_headers = [('Content-Type', 'text/plain')] start_response(status, response_headers) return [response_body] # for testing only server = make_server('localhost', 8051, application) server.serve_forever() Publishing ◦ upload this program to web server directory (after removing main statements) ◦ lo.py Testing ◦ Run this program by lauching test server ◦ Enter URL on the browser or hello.py:
MVC ◦ model: data to be displayed and modified ◦ view: display the data of the model to the user typically implemented by templates ◦ controller reacts to user actions tells the model to modify the data, and tells the view code what to display Frameworks for web app development in Python ◦ Django: Google App Engine: a PaaS ◦