Writing a trivial application to display "Hello, world!" is something of a computing tradition but it's surprisingly educational. = Application Structure = We are going to implement a simple application but we'll wind up with a lot more potential functionality than we'll use. In its simplest form, this entire page could be rendered using just the html: {{{
Hello, World! }}} Static pages like this aren't useful in an interactive sense. Making an Albatross application to do this is a little more complicated because we need to initialise a lot of extra machinery even though we won't use the bulk of it. = File Organisation = We'll use a model-view-controller to drive the application even though it's overkill. This is immediately simplified because it's a display-only application so there are no data models so we'll only need a view and controller. XXX Pretty diagram of file structure here: -- hell.cgi -- pages/hello.html -- ???/hello.py Here's the main app in {{{hello.cgi}}}: {{{#!python #! /usr/bin/env python from albatross import RandomModularSessionApp, SessionAppContext from albatross.cgiapp import Request class App(RandomModularSessionApp): def __init__(self): RandomModularSessionApp.__init__(self, base_url='hello.cgi', page_path='pages', start_page='hello', secret='-=-secret-=-', session_appid='random') def create_context(self): # XXX is this necessary? return SessionAppContext(self) if __name__ == '__main__': app = RandomModularSessionApp(base_url='hello.cgi', page_path='pages', start_page='hello', secret='-=-secret-=-', session_appid='random') app.run(Request()) }}} This is the model part of the app where we display to the user (???/hello.py): {{{#!python def page_display(ctx): ctx.locals.message = 'Hello, world!' ctx.run_template('hello.html') }}} And here's what the html to display (in html/hello.html): {{{