2082
Comment:
|
2089
|
Deletions are marked like this. | Additions are marked like this. |
Line 42: | Line 42: |
return AppContext(self) | return SessionAppContext(self) |
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 so an application server like Albatross needs some extra functionality which calls for some extra work.
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 from albatross import RandomModularSessionApp, SessionAppContext
2 from albatross.cgiapp import Request
3
4 class App(RandomModularSessionApp):
5 def __init__(self):
6 RandomModularSessionApp.__init__(self,
7 base_url='hello.cgi',
8 page_path='pages',
9 start_page='hello',
10 secret='-=-secret-=-',
11 session_appid='random')
12
13 def create_context(self): # XXX is this necessary?
14 return SessionAppContext(self)
15
16 if __name__ == '__main__':
17 App().run(Request())
This is the model part of the app where we display to the user (???/hello.py):
And here's what the html to display (in html/hello.html):
<html> <head> </head> <body> <al-value expr="message"> </body> </html>