04.08.2014 Views

o_18ufhmfmq19t513t3lgmn5l1qa8a.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

328 CHAPTER 15 ■ PYTHON AND THE WEB<br />

<br />

Change name <br />

<br />

<br />

<br />

<br />

""" % name<br />

Figure 15-2 shows the result of accessing the script in Listing 15-7 through a Web server.<br />

Figure 15-2. The result of executing the CGI script in Listing 15-7<br />

One Step Up: mod_python<br />

If you like CGI, you will probably love mod_python. It’s an extension (module) for the Apache<br />

Web server, and you can get it from the mod_python Web site, http://modpython.org. It makes<br />

the Python interpreter directly available as a part of Apache, which makes a whole host of<br />

different cool stuff possible. At the core, it gives you the ability to write Apache handlers in<br />

Python, as opposed to in C, which is the norm. The mod_python handler framework gives you<br />

access to a rich API, uncovering Apache internals and more.<br />

In addition to the basic functionality, however, it comes with several handlers that can<br />

make Web development a more pleasant task. There is the CGI handler, which lets you run CGI<br />

scripts using the mod_python interpreter, considerably speeding up their execution; there is<br />

the PSP handler, which lets you mix HTML and Python code to create executable Web pages, or<br />

Python Server Pages; and there is the publisher handler, which lets you call Python functions<br />

using URLs. In this section, I will focus on these three standard handlers; if you want to write<br />

your own custom handlers, you should check out the mod_python documentation.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!