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  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM developerWorks
 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? 
PYTHON

A Brief Look at Mod_Python
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 19
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Python source examples are wrongly formatted and so syntactically incorrect. Please...
       · The examples won't work, since the indentation has been lost. Hopefully the author...
       · We have changed the code samples to the proper indentation that the author provided....
       · I installed mod_python in my apache server but apache is not starting now. When I...
       · Nice Intro - thanx!The following example needed a <html> tag, due to Mime...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway