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.
- 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
-
v7
|
v8
|
|
35 | 35 | == Rendering Genshi Templates == |
36 | 36 | |
37 | | TODO |
| 37 | The `diva.templating` module provides convenience functions for rendering Genshi templates. |
38 | 38 | |
39 | | == Default Template Data == |
| 39 | First, 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. |
40 | 40 | |
41 | | Diva makes a number of objects available for use in Genshi by default: |
| 41 | Note 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') |
| 47 | def style(request, response, font_size=1): |
| 48 | return 'html { font-size: %sem; }' % font_size |
| 49 | }}} |
| 50 | |
| 51 | If 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 | |
| 55 | Diva makes a number of objects available for use in Genshi templates by default: |
42 | 56 | |
43 | 57 | `app`:: The [ApplicationObject Application] object |
… |
… |
|
58 | 72 | == Builtin Request Handlers == |
59 | 73 | |
60 | | Diva comes with a couple of generic request handlers that can be used as-is with some parameterization. |
| 74 | Diva comes with a couple of generic request handlers that can be used as-is with some parameterization in UrlRouting. |
61 | 75 | |
62 | 76 | `diva.routing:delegate`:: Delegate request processing to a different WSGI application. |