|Home About Us Services Clients Resources Blog Careers Orderbox™||contact us Site map links|
What is Spyce?
Spyce is a mature Python server pages technology and one of the most versatile around. It works analogous to PHP except the language used is Python. Unlike Python frameworks and web stacks such as Django and TurboGears, Spyce requires very little additional knowledge to get started with and lets you utilize your existing knowledge of Python libraries without much additional fuss.
Python's innate expressiveness means that even without resorting to a fancy framework, one can creating a complex web application in html-embedded script style and still retain conciseness that promotes code manageability. Spyce includes a handful of minimalistic but powerful mechanisms such as custom tags and Spyce lambdas that imbue the straightforward server pages development style with more power and enable it to tackle demanding tasks that would probably already require a framework under PHP.
Another important benefit of using Spyce over more complex Python web technology like Django/TurboGears/etc... is that it will be much easier to find programmers to inherit your codebase if you ever find yourself needing to do this. Instead of looking for a Django, TurboGears, CherryPy, etc... expert, you only need to look for someone versed in Python itself.
1. Use <% and %> instead of [[ and ]]
The Spyce documentation teaches usage of [[ and ]] as server
script body delimiters, but Spyce will happily support the more
familiar ASP/JSP style <% and %> delimiters which most
people might be more comfortable with. For our development work here
at Neotitans, we use this convention because it lets our favorite text
editor, SciTE, color highlight
the Python code within our Spyce scripts very nicely as shown below.
2. Accessing POST and GET variables in Spyce (.spy) scripts
Every Spyce script contains the implicit module
<%\ req.get1("userid") # returns value of GET variable userid as a string req.post1("userid") # returns value of POST variable userid as a string req.getpost1("userid") # returns value of GET variable userid if present or # of POST variable otherwise req.postget1("userid") # like the last example, but checks in reverse order req.get("userid") # Works like the above calls, but returns the values req.post("userid") # of the GET/POST variables as a list of strings. req.getpost("userid") # Useful if you are expecting multiple values within req.postget("userid") # a single GET or POST variable. %>
3. How to exit a Spyce script in the middle of code without showing an exception message
When you want to terminate your Spyce script execution
somewhere in the middle of the code, you might be tempted to
<html><body> <%\ userid=req.getpost1("userid") if userid: print "Hello ",userid else: return # will not print closing body and html tag below %> </body></html>
See http://spyce.sourceforge.net/docs/docs-runtime_except.html for more detailed info.
© 2020 by Andy Sy
Web Development / Rich Internet Applications (RIA) Development
|© 2003-2019 Neotitans Technologies Inc.||contact/hire us|