spyce
home
license
community
download
examples
resources
wishlist
contrib (@sf)
documentation
intro
lang
runtime
modules
tags
install
exits
sourceforge
statistics
freshmeat

Documentation - Introduction
[[ Spyce ]]
Python Server Pages
by Rimon Barr

Prev: 1.2 - Design Goals Up: 1 - Introduction Next: 2 - Language

1.3. Getting Started

After installing Spyce, you are ready to write your first Spyce page. Start by editing a file called hello.spy in some web-published directory (a directory served by your webserver, and where .spy files will be handled correctly). Enter the following Spyce code:

examples/hello.spy
<html><body>
  Hello [[print 'world!',]]
  [[ for i in range(10): { ]]
    [[=i]]
  [[ } ]]
</body></html>
Run this code.
(requires Spyce-enabled web server)

Note: This manual assumes a knowledge of Python and focusses exclusively on Spyce. If you do not already know Python, it is easiest to learn via this short tutorial, and has extensive documentation.

Save the file, and execute:

spyce hello.spy

The output should be:

  <html><body>
    Hello world!
      0  
      1  
      2  
      3  
      4  
      5  
      6  
      7  
      8  
      9 
  </body></html>

You might want to see this inside a browser! For this, you need a Spyce enabled web server. Spyce can integrate into a number of web environments, but the easiest for the purposes of "getting started" is the built-in Spyce web server. You can run it by typing:

spyce -l -p port root

Replace port with some other port number, or omit the -p switch and assume the default, which is port 80. Replace root with the root document directory; the default is the current directory. All web requests are served relative to the server's root document directory.

Windows users should note that there is no command called spyce installed on their system. They should execute, instead:

C:\python_directory\python.exe C:\spyce_directory\spyce.py ...

Now, if you fire up your browser, and browse to:

http://your.domain:8080/some_path/hello.spy

then you will see the file: root/some_path/hello.spy and the output should be:

  Hello world! 0  1  2  3  4  5  6  7  8  9

If you are curious, you can see the Python source code of the compiled Spyce script. It sometimes helps to understand the transformation that is taking place. Execute:

spyce -c hello.spy

That's all folks! You have just written your first Spyce script. Having performed the obligatory Hello world! ritual, we now describe the Spyce language more systematically.


Prev: 1.2 - Design Goals Up: 1 - Introduction Next: 2 - Language


© 2002-07 Rimon Barr
email: rimon@acm.org
Spyce Powered SourceForge Logo [[ Spyce ]]
Python Server Pages
version 1.3.13