Python
  Home arrow Python arrow Page 4 - Using Spyce
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

Using Spyce
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 9
    2006-01-17


    Table of Contents:
  • Using Spyce
  • Basic Syntax
  • Active Tags
  • Handling Form Data

  • 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


    Using Spyce - Handling Form Data
    ( Page 4 of 4 )

    Spyce contains a few methods that deal with handling form data. You've already seen one of them briefly, but let's take a look at some more of them:

    [[\
    import random
    methods = [request.get, request.get1, request.post, request.post1,\
               request.getpost, request.getpost1, request.postget, request.postget1]
    genList = [[spy! method:
       <b>[[=str(method).replace('<', '&lt;')]]</b><br />
       [[ for field in ('A','B','C'): { ]]
          [[=field]]: [[=method(field)]]<br />
       [[ } ]]
       <br />]]
    ]]

    [[-- Handle processing --]]
    [[ if request.getpost1('A', None): { ]]
       [[ for method in methods: { ]]
          [[ genList(method) ]]
       [[ } ]]
    [[ } ]]

    [[-- The actual form --]]
    <form method='[[=random.choice(['POST', 'GET'])]]'>
    A: <input type='text' name='A' /><br />
    B: <input type='text' name='B' /><br />
    C: <input type='text' name='C' /><br />
    <input type='submit' value='Submit' />
    </form>

    The script above sends form data through either the “GET” or “POST” methods randomly, and then it displays the results of several of Spyce's methods, which are listed in the methods list. Below that, we define getList. Notice, however, that getList deals with Spyce itself. The “[[!spy X]]” structure simply defines a function that can be accessed later. In this case, it's a function that calls a method with either “A”, “B” or “C” as an argument—our field names. Later in the script, we call this function with each item in methods. Observe what each method returns, and observe what happens when “GET” and “POST” data are mixed.

    Conclusion

    Spyce has a lot to offer to web developers and developers looking for dynamic content in general. One of its main advantages is that it can work alone, with Apache, with mod_python, with FastCGI or with CGI without any major modifications. If one method is not available to you, there's always more to fall back on. It offers several tags that can be used for unique purposes, and it offers a way for developers to save time by using active tags. Of course, there are also plenty of others features of Spyce that cannot be covered in a single article. Spyce isn't the only way of embedding Python code, but it is arguably the most feature-filled way.



     
     
    >>> 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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek