|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 very much like straight PHP except that the language used is Python. Unlike Python frameworks and web stacks such as Django and TurboGears, Spyce requires very little additional study to get started with and lets you utilize your existing knowledge of Python libraries almost immediately.
One of the most important benefits of using Spyce over more arcane Python web technologies such as 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 someone who knows Python itself.
Python's expressiveness means that complex web applications written using the html-embedded script style can still retain a conciseness that promotes code manageability. Combining Python's innate expressivity with a handful of minimalistic, but powerful mechanisms such as custom tags and Spyce lambdas, Spyce gives power far exceeding what you can expect with plain PHP, enabling you to tackle demanding tasks that would otherwise be difficult without a framework. Following are a list of important tips and techniques that may be hard to figure out from the native Spyce documentation (which beginners are apt to find confusing to navigate). Neotitan's VPS hosting packages support mod_python and Python 2.5.x and will let you securely host Spyce-based websites with a minimum of fuss.
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
<%\ request.get1("userid") # returns value of GET variable userid as a string request.post1("userid") # returns value of POST variable userid as a string request.getpost1("userid") # returns value of GET variable userid if present or # of POST variable otherwise request.postget1("userid") # like the last example, but checks in reverse order request.get("userid") # Works like the above calls, but returns the values request.post("userid") # of the GET/POST variables as a list of strings. request.getpost("userid") # Useful if you are expecting multiple values within request.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=request.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.
4. Configuring Spyce to work with lighttpd and FastCGI
Step 1. Unpack Spyce into an appropriate directory such
Step 2. Under the
Step 3. Under the
Step 4. Insert and modify
## change uid to <uid> (default: don't care) server.username = "www" ## change uid to <uid> (default: don't care) server.groupname = "www" #### accesslog module accesslog.filename = "/var/log/lighttpd/access.log" # files to check for if .../ is requested index-file.names = ( "index.spy", "index.html", "index.htm", "default.htm" ) #### fastcgi module fastcgi.server = ( ".spy" => ( "localhost" => ( "socket" => "/var/run/lighttpd/spy-fastcgi.socket", "bin-path" => "/usr/local/spyce-2.1/spyceCGI.py" ) ) )
Step 5. As of Spyce 2.1.3, I needed to modify the following line in
try: path = findScriptFile(environ['PATH_TRANSLATED'])
try: path = findScriptFile(environ['SCRIPT_FILENAME'])
in order to get fastcgi Spyce to work.
Want to tip via bitcoin?
(address string below for double checking)
© 2020 by Andy Sy
Web Development / Rich Internet Applications (RIA) Development
|© 2003-2019 Neotitans Technologies Inc.||contact/hire us|