Differences between revisions 6 and 8 (spanning 2 versions)
Revision 6 as of 2007-03-10 12:53:24
Size: 92
Editor: 88
Comment:
Revision 8 as of 2011-02-15 06:05:17
Size: 2369
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Hello World =
Line 2: Line 3:
An Albatross version of the ''classic'' (ahem) hello world application.
Line 3: Line 5:
== Purpose ==
Line 4: Line 7:
HACKED BY UKW TİM // UNKNOWNS.US To demonstrate:
Line 6: Line 9:
Uqur-X // SLAYER // CRAZY DORUK // ASİKRAL //  * a very basic application
 * registration of page classes
 * sending a HTML template file to the client

== Overview ==

The {{{HelloWorld}}} class simply initialises its base class, Albatross's prepackaged {{{SimpleApp}}}, and then registers the only page in the application, {{{StartPage}}}. The parameters passed to the {{{SimpleApp}}} constructor are:

 * {{{base_url}}} - the path on the web server where the application is hosted. {{{base_url}}} is only used to generate links to other pages and so is largely irrelevant in this example.
 * {{{template_path}}} - the directory containing the application's template files
 * {{{start_page}}} - the page to display by default
 * {{{secret}}} - an application-specific value used to ensure the integrity of session data that is sent to the browser

{{{StartPage}}} contains only one method, {{{page_display}}}, that tells Albatross to render the template file {{{startpage.html}}}.

Although it is not essential in this application (since there is only one page) it is customary for each page class to contain a class variable called {{{name}}} which uniquely identifes the page. The page's {{{name}}} is used in links.

== Source Code ==

=== helloworld.py ===
{{{
#!python
import albatross
from albatross import cgiapp
                                                                                
class HelloWorld(albatross.SimpleApp):
    def __init__(self):
        albatross.SimpleApp.__init__(
                self,
                base_url = '/',
                template_path = '.',
                start_page = StartPage.name,
                secret = 'secret')
        self.register_page(StartPage.name, StartPage())
                                                                                
class StartPage:
    name = 'start'
    def page_display(self, ctx):
        ctx.run_template('startpage.html')
                                                                                
if __name__ == '__main__':
    app = HelloWorld()
    app.run(cgiapp.Request())
}}}

=== startpage.html ===
{{{
<html>
  <head>
    <title>Hello World</title>
  </head>
  <body>
    <p>Hello World.</p>
  </body>
</html>
}}}

Hello World

An Albatross version of the classic (ahem) hello world application.

Purpose

To demonstrate:

  • a very basic application
  • registration of page classes
  • sending a HTML template file to the client

Overview

The HelloWorld class simply initialises its base class, Albatross's prepackaged SimpleApp, and then registers the only page in the application, StartPage. The parameters passed to the SimpleApp constructor are:

  • base_url - the path on the web server where the application is hosted. base_url is only used to generate links to other pages and so is largely irrelevant in this example.

  • template_path - the directory containing the application's template files

  • start_page - the page to display by default

  • secret - an application-specific value used to ensure the integrity of session data that is sent to the browser

StartPage contains only one method, page_display, that tells Albatross to render the template file startpage.html.

Although it is not essential in this application (since there is only one page) it is customary for each page class to contain a class variable called name which uniquely identifes the page. The page's name is used in links.

Source Code

helloworld.py

   1 import albatross
   2 from albatross import cgiapp
   3                                                                                 
   4 class HelloWorld(albatross.SimpleApp):
   5     def __init__(self):
   6         albatross.SimpleApp.__init__(
   7                 self,
   8                 base_url = '/',
   9                 template_path = '.',
  10                 start_page = StartPage.name,
  11                 secret = 'secret')
  12         self.register_page(StartPage.name, StartPage())
  13                                                                                 
  14 class StartPage:
  15     name = 'start'
  16     def page_display(self, ctx):
  17         ctx.run_template('startpage.html')
  18                                                                                 
  19 if __name__ == '__main__':
  20     app = HelloWorld()
  21     app.run(cgiapp.Request())

startpage.html

<html>
  <head>
    <title>Hello World</title>
  </head>
  <body>
    <p>Hello World.</p>
  </body>
</html>

None: HelloWorld (last edited 2011-02-15 06:05:17 by localhost)