Python
  Home arrow Python arrow Page 5 - A Brief Look at Mod_Python
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PYTHON

A Brief Look at Mod_Python
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 20
    2005-04-25


    Table of Contents:
  • A Brief Look at Mod_Python
  • Installing Mod_Python
  • Getting Started
  • Creating Handlers and Working with the API
  • Python Server Pages

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    A Brief Look at Mod_Python - Python Server Pages
    ( Page 5 of 5 )

    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:

    AddHandler mod_python.psp
    PythonHandler mod_python.psp

    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:

    <% # Python code here %>

    You can also print out single items by putting an equal sign in, just as you would with PHP:

    <%=variableName%>

    Here an example:

    <%
    # Import a Module
    import math
    %>
    <html>
    <head>
    <title>Python Server Pages Test</title>
    </head>
    <body>
    The square root of 25 is <%=math.sqrt ( 25 )%>. The square root of 50 is <%=math.sqrt ( 50 )%>.
    </body>
    </html>

    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.



     
     
    >>> More Python Articles          >>> More By Peyton McCullough
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek