Not that this is particularly semwebby, but whatever.

The files below are a simple example of using web.py with fastCGI and Cheetah (which is how I'm using Redland on the daylily site.) Just put the files in your document root. You do need to have Cheetah Templating installed if you want to use web.render(). If you don't want templating, you can just 'print' the output, and it will go to the client.

File permissions are important! Set them as follows:

  • chmod 755 index.fcgi
  • chmod 644 .htaccess
  • chmod 644 templates/index.tmpl

/index.fcgi

#!/home/USERNAME/usr/bin/python2.4
import web

## Note that you need web.py and Cheetah Templating installed!
## Visit http://webpy.org and http://cheetahtemplate.org

urls = (
  '/(.*)', 'hello'
)

class hello:
  def GET(self, name):
    if not name: name="World"
    web.header('Content-Type', 'text/html')
    web.render("index.tmpl", terms={'name':name}) # Note - leave out templates/ from the path!

if __name__ == "__main__":
  web.runwsgi = web.runfcgi # force to run as Fast CGI
  web.run(urls)

/templates/index.tmpl

<html>
<head>
<title>My Test Page</title>
</head>
<body>
Hello $name!
</body>
</html>

/.htaccess

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /
  RewriteCond %{REQUEST_URI} !^/static
  RewriteCond %{REQUEST_URI} !^/favicon.ico$
  RewriteCond %{REQUEST_URI} !^(/.*)+index.fcgi/
  RewriteRule ^(.*)$ index.fcgi/$1 [PT]
</IfModule>

Comments