Now I'll introduce Python Server Pages. Languages like PHP have been made popular due to their ability to be embedded directly into HTML. Python Server Pages allow Python code to be embedded into HTML pages. Python Server Pages aren't terribly difficult to understand, and I believe showing you would be a lot better than telling you, so we'll jump right in. Create a directory named pypsp, and add this to its .htaccess file:
Now let's get into some code. Python code is enclosed between less-than and greater-than signs, postfixed and prefixed with percent signs. For example:
You can also print out single items by putting an equal sign in, just as you would with PHP:
Here an example:
Save it as test.psp and point your browser to it. Interesting, eh? Conclusion As you've seen throughout this article, mod_python is a very powerful addition to the Apache Web server. It allows control over even Apache itself through handlers, which are easily created with mod_python. The publisher handle and the psp handle make Web development in Python a lot easier than it already is, and allow it to better compete with popular Web development languages such as PHP and ASP. What this article outlines is definitely not all of mod_python. Mod_python contains much more power than this article can tell about, but that power is the topic of another article on another day. Until then, good luck.
blog comments powered by Disqus |