Revised 2015 Nov 201
The World Wide Web was born in 1990, at first with only static web pages; CGI came along in 1993.
Java (1995) gained popularity initially through applets, Java programs running in the web browser (client side). Servlets (1997) are the server-side counterpart.
With servlets, a Java interpreter runs within the web server (usually a special purpose web server such as Tomcat).
Advantages:
Advantages:
References:
mod_python (ca. 2000) was developed for the Apache web server to avoid the cost of starting up the Python interpreter (starting a new process) for each CGI script run. Similar modules exist for some other languages, e.g., mod_php, mod_perl.
These Apache web server components (mod_python, mod_php, mod_perl); are similar to servlets, in that they run an interpreter in the web server.
Advantage:
Disadvantage:
WSGI (Python Web Server Gateway Interface) is a newer interface which makes mod_python generally obsolete. There is a mod_wsgi for Apache httpd (which is officially Python 2 but maybe also supports Python 3). There are probably implementations for other web servers.
PEP 333 was the original definition for WSGI, now superseded by PEP 3333 for Python 3. (PEP = Python Enhancement Proposal)
The Python standard library contains a WSGI-enabled HTTP server.
There were some difficulties in porting WSGI to Python 3: the rigid distinction between bytes and str(ing) objects seems pre-eminent. In general, HTTP deals with bytes; web pages are delivered as bytes encoding strings (using some encoding), and strings in Python 3 are Unicode strings, which are not bytes and cannot be directly combined with bytes (for example, b'abc' + 'def' is an error).
WSGI middleware means “[WSGI-based software] components that that look like an application to their containing server, while acting as a server for their contained application”. Such middleware can perform services for their contained applications such as preprocessing requests and postprocessing responses.
Example: we can use the Python 3 standard library’s WSGI-enabled HTTP server to run Listing 11–1 (p. 184) easily:
So far, we have considered alternatives to CGI that are designed to make more efficient use of the computer hardware. Programmers are another scarce resource that must be used efficiently. Web frameworks provide higher-level APIs, which can help programmers to work more productively. However, there is a start-up cost: the programmer must learn the web framework.
Web frameworks are also called “web application frameworks”, “web server frameworks”, etc.
WSGI provides a low-level API, so it is rarely used directly by web developers (as distinguished from web framework developers).
The Python web frameworks nowadays are built over WSGI, and since WSGI is a “standard” interface to web servers, it makes the web frameworks easier to use with a variety of servers.
A major goal of WSGI is to make any Python web framework usable with any web server.
Web frameworks tend to be large and complex; entire books could be written about Django and Zope, and we would need another course to consider them in serious detail.
(We will skip the details of bottle in order to focus on Tornado, a slightly larger web framework for Python. Tornado will have its own page(s) of notes.)
However, bottle is a small (“micro”) web framework which we can use to demonstrate the most basic ideas.
Bottle has its own server, for development and testing; so we can easily run the examples. To run these you also need bottle.py. On merlin, just check out the darcs bottle examples repository and run as follows:
$ darcs get /home/info/share/i320/bottle
$ cd bottle
$ python3 tut01.pyOff merlin, you should be able to check out the repository as follows (if you have darcs installed on your computer):
darcs get USER@merlin.iue.edu:/home/info/share/i320/bottle
substituting your IU user id for USER.
@ notation for “decorators”. Decorators are functions applied to functions, returning functions.Java and JavaScript enable programs to run in the web browser, avoiding the need to send a request to a server and wait for the server to respond.
Ajax (Asynchronous JavaScript and XML) allows the browser to exchange data with the server “in the background”; Comet enables the web server to push streaming data.
@ was victorious), but little about the meaning