lib/handler.py
changeset 8 0ce1f471e9d7
parent 7 d6a8258bd90e
child 9 2a47b00f60b0
equal deleted inserted replaced
7:d6a8258bd90e 8:0ce1f471e9d7
     1 """
     1 """
     2     The actual application behaviour, i.e. generating a Response from a Request :)
     2     The actual application behaviour, i.e. generating a Response from a Request :)
     3 """
     3 """
     4 
     4 
     5 import http, page
     5 import http, page, template
     6 
     6 
     7 def handle_request (request) :
     7 def handle_request (request) :
     8     """
     8     """
     9         Take the Request, and return a Response
     9         Take the Request, and return a Response
    10     """
    10     """
    11 
    11 
    12     return http.Response("Hello World")
    12     # determine the page name
       
    13     page_name = request.get_page_name()
    13 
    14 
       
    15     # get the page handler
       
    16     p = page.lookup(page_name)
       
    17 
       
    18     # render the template
       
    19     response_data = template.render("layout",
       
    20         site_root_url   = request.get_script_dir(),
       
    21         page_title      = p.get_title(),
       
    22         page_content    = p.get_content(),
       
    23     )
       
    24     
       
    25     # return the response
       
    26     return http.Response(response_data)
       
    27