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  
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 
 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

Using Spyce
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 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:
      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

    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.


    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.

       · Suprise, suprise, this article covers Spyce. While some of the basics are covered,...
       · From what I saw I am not sure if would use it. Having all those brackets to encase...
       · Great article, I am looking for a powerful, easy-to-install alternative to Perl and...
       · Jumped the gun - the if-else example isn't intended to be run without some code in...
       · I was about to go with Webware and Cheetah but I found Spyce in the nick of time. ...
       · Having some experience from PHP I have found python by 'accident' and I fall in love...
     

       

    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