close Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 7 and Version 8 of RequestHandlers


Ignore:
Timestamp:
Jul 9, 2008, 10:06:25 AM (16 years ago)
Author:
cmlenz
Comment:

Add basic explanation of template rendering

Legend:

Unmodified
Added
Removed
Modified
  • RequestHandlers

    v7 v8  
    3535== Rendering Genshi Templates ==
    3636
    37 TODO
     37The `diva.templating` module provides convenience functions for rendering Genshi templates.
    3838
    39 == Default Template Data ==
     39First, there's the `@output` decorator, which you use to specify the name of the template file, the serialization method, the response MIME type and encoding, and other serialization options such as the `DOCTYPE` to use and so on.
    4040
    41 Diva makes a number of objects available for use in Genshi by default:
     41Note that all of these are optional. For example, you can omit the template file name for a response that doesn't involve template rendering, and just use the `mimetype` and `encoding` options:
     42
     43{{{
     44#!python
     45@caching(max_age=timedelta(days=7))
     46@output(mimetype='text/css', encoding='utf-8')
     47def style(request, response, font_size=1):
     48    return 'html { font-size: %sem; }' % font_size
     49}}}
     50
     51If you do want to render a template, use the `render()` function to return a Genshi stream from the request handler. You pass any template data into the `render()` function as keyword arguments, and it will generate an output stream from the template based on the template data. The `render()` function also lets you override the template filename specified using the `@output` decorator: simple pass the template name as the first (and only) positional argument into `render()`.
     52
     53=== Default Template Data ===
     54
     55Diva makes a number of objects available for use in Genshi templates by default:
    4256
    4357 `app`:: The [ApplicationObject Application] object
     
    5872== Builtin Request Handlers ==
    5973
    60 Diva comes with a couple of generic request handlers that can be used as-is with some parameterization.
     74Diva comes with a couple of generic request handlers that can be used as-is with some parameterization in UrlRouting.
    6175
    6276 `diva.routing:delegate`:: Delegate request processing to a different WSGI application.