We have just seen how to run programs on our own computer. This chapter shows how to port your programs to the web using what you have learned up to this point in addition to some new techniques. The main advantage of making a program available on the Web is that
it can reach more users without the need for them to install a copy of the program and to have a Python installation. It also helps users who do not have the permissions necessary to install software on a particular machine. Sometimes the program accesses huge databases that can’t be installed on the end user’s hard drive. In order to make web programming it is not enough to know Python. It is
also necessary to have a basic understanding of Web servers and Web page design using HTML. Both of these topics are beyond the scope of this book, for which reason I recommend that you read up on them if you have never designed a WEB page before. Knowing the basics of HTML has special importance as most IT Labs have staff dedicated to the setup and maintenance of the WEB server but the HTML design is something that they will rarely do for you. For more information on HTML, please see the “Additional Resources” section. Concerning the Web server, besides using the one provided by the institution where you work you can use for learning purposes the one included with DNA Virtual Desktop Edition that is included with this book. There are several ways to use Python on a Web server, CGI (Common
Gateway Interface), mod python andWSGI (Web Server Gateway Interface). CGI is the most used method, as it is the easiest to configure and is available on almost all Web servers without having to install additional software. It is essentially a protocol to connect an application, written in any language with a Web server. mod python in particular consists of an Apache Module that integrates Python with the Web server. The advantage of this approach is the fast execution time of our scripts, since the Python interpreter is loaded with the Web server.1 The disadvantage is that it works “only” with the Apache Web server, which is a minor disadvantage as we are probably already using Apache as it is the most used Web server on the Internet.
are several implementations. The main advantage of WSGI is that once you have made a WSGI application, it can be deployed in any WSGI compatible server (or even using a Python provided Web server). As in mod python, the execution speed is better than CGI, because there is no overhead for starting the Python interpreter on each request.