16.01.2014 Views

Beginning Python - From Novice to Professional

Beginning Python - From Novice to Professional

Beginning Python - From Novice to Professional

SHOW MORE
SHOW LESS

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 <strong>Python</strong> 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 <strong>to</strong> write Apache handlers in<br />

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

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

In addition <strong>to</strong> 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 <strong>Python</strong> code <strong>to</strong> create executable Web pages, or<br />

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

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

your own cus<strong>to</strong>m 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!