An Albatross application can be deployed in a web server as a CGI (albatross.cgiapp), FastCGI (albatross.fcgiapp) or mod_python (albatross.apacheapp) application. It can also be deployed as a standalone HTTP server (albatross.httpdapp). To demonstrate each of these deployment options we're going to use a simple, single page application and a series of deployment scripts.
If you want to rebuild this entire example then you can copy all of the following files to a single directory that is accessible to Apache. (Don't forget to make the CGI scripts executable.)
First, here's the application module, app.py:
1 from albatross import SimpleApp 2 3 class Home: 4 name = 'home' 5 def page_display(self, ctx): 6 ctx.run_template('home.html') 7 8 class App(SimpleApp): 9 def __init__(self, base_url, base_dir): 10 SimpleApp.__init__( 11 self, 12 base_url=base_url, 13 template_path=base_dir, 14 start_page=Home.name, 15 secret='-=secret=-' 16 ) 17 self.register_page(Home.name, Home())
And here's the home.html template:
<html> <body> <p>Boo!</p> </body> </html>
One thing to note is that app.py contains no deployment code. It's possible to put the deployment code into the application's main module but we're going to use separate "connector" scripts for this demonstration so that the application code needs no changes.
The deployment scripts, or "connector" scripts as I like to call them, are extremely simple. Their only purpose is to create an application instance and connect it to the web server. Hopefully the scripts are obvious so I will not go into much (if any) detail.
As mentioned above, I used Apache to test these. Here's a simple .htaccess file that may help:
Options +ExecCGI AddHandler cgi-script cgi AddHandler fastcgi-script fcgi AddHandler python-program py PythonHandler connector
CGIs are run from the directory they are in so the application's base_dir can be '.'.
from albatross import cgiapp import app theApp = app.App('connector.cgi', '.') theApp.run(cgiapp.Request())
FastCGIs, like CGIs, are run from the directory of the script.
from albatross import fcgiapp import app theApp = app.App('connector.fcgi', '.') while fcgiapp.running(): theApp.run(fcgiapp.Request())
mod_python programs run inside Apache. mod_python adds the script's directory to the sys.path but the current working directory could be anywhere so this time we need to be explicit about where the application is installed so that the templates can be found.
The albatross.httpdapp module contains a simple, standalone HTTP server (based on Python's BaseHTTPServer) and a helper script, al-httpd.
from albatross import httpdapp import app theApp = app.App('/', '.')
To run it use "al-httpd standalone.theApp 8001".