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:
-
Jun 25, 2008, 1:01:38 PM (16 years ago)
- Author:
-
cmlenz
- Comment:
-
--
Legend:
- Unmodified
- Added
- Removed
- Modified
-
v2
|
v3
|
|
13 | 13 | |
14 | 14 | This defines a function called `index` that will respond to requests by rendering the template `index.html`. |
| 15 | |
| 16 | == URL Parts as Parameters == |
| 17 | |
| 18 | Any dynamic parts of the URLs defined in the UrlRouting are passed to the request handler as additional parameters. For example: |
| 19 | |
| 20 | {{{ |
| 21 | #!python |
| 22 | from datetime import datetime |
| 23 | from diva import app |
| 24 | from diva.templating import output, render |
| 25 | |
| 26 | @output('index.html') |
| 27 | def monthly(request, response, year, month): |
| 28 | return render(month=datetime(year, month, 1)) |
| 29 | |
| 30 | app.routing.add('/archives/{year:\d+}/{month:\d+}/', monthly) |
| 31 | }}} |
| 32 | |
| 33 | Note that in this particular case, the values for `year` and `month` are automatically converted to numbers, due to the use of the `\d+` pattern in the route path. |