Differences between revisions 5 and 6
Revision 5 as of 2006-08-15 00:49:59
Size: 2115
Editor: BenGolding
Comment:
Revision 6 as of 2006-08-15 01:07:05
Size: 2181
Editor: BenGolding
Comment:
Deletions are marked like this. Additions are marked like this.
Line 16: Line 16:
Static pages like this aren't useful in an interactive sense so an application server like Albatross needs some extra functionality which calls for some extra work. 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.

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:

<head>
 <head>
 </head>
 <body>
  Hello, World!
 </body>
</html>

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:

   1 #! /usr/bin/env python
   2 
   3 from albatross import RandomModularSessionApp, SessionAppContext
   4 from albatross.cgiapp import Request
   5 
   6 class App(RandomModularSessionApp):
   7     def __init__(self):
   8         RandomModularSessionApp.__init__(self,
   9                                          base_url='hello.cgi',
  10                                          page_path='pages',
  11                                          start_page='hello',
  12                                          secret='-=-secret-=-',
  13                                          session_appid='random')
  14 
  15     def create_context(self):   # XXX is this necessary?
  16         return SessionAppContext(self)
  17         
  18 if __name__ == '__main__':
  19     App().run(Request())

This is the model part of the app where we display to the user (???/hello.py):

   1 def page_display(ctx):
   2     ctx.locals.message = 'Hello, world!'
   3     ctx.run_template('hello.html')

And here's what the html to display (in html/hello.html):

<html>
 <head>
 </head>
 <body>
  <al-value expr="message">
 </body>
</html>

None: "Hello_world"_example (last edited 2011-02-15 06:05:18 by localhost)