# HG changeset patch
# User David Barts The header is optional and consists of lines starting with an octothorpe
(#) character. With the exception of the It is possible to include whitespace and special characters in arguments
to the Header directives that don't take arguments as a rule simply ignore them.
For example, Error pages supersede the standard Bottle error handling, and are created
- by using the .pspx Template Files
Introduction
- Files ending in a .pspx extension define both
- routes and templates. The files have two parts: a header and a body.
+ Files ending in a .pspx extension define both routes and
+ templates. The files have two parts: a header and a body.
The Header
#rem
header, all
@@ -19,20 +19,19 @@
#end
#errors
#forward
#forward
may itself contain a #forward
,
but attempts to create a #forward
loop are not allowed and
- will cause a TinCanError to be raised. Note
- that unlike calls to app.forward()
, the #forward
- header is resolved at route-creation time; no extra processing will
- happen at request time.app.forward()
, the #forward
header
+ is resolved at route-creation time; no extra processing will happen at
+ request time.
#hidden
#python
#rem
#template
#forward
, #python
, and #template
@@ -57,22 +56,22 @@
example, #python "space case.py"
.#end headers
has the same effect as #end
.
+ Error Pages
#errors
page header. Error pages have no
- associated code-behind; they consist of templates only. Error page
- templates are provided with two variables when rendering:
-
+ by using the error
bottle.HTTPError
object associated with this error.request
bottle.Request
object associated with this error.#errors
page header. The #hidden
+ and #method
header directives are ignored in error pages
+ (error pages are effectively hidden anyhow, by virtue of never having
+ normal routes created for them).
The #errors
directive takes a list of numeric error codes
(values from 400 to 599 are allowed); the page is created to handle the
specified errors. If no error codes are specified, the page will handle
all errors. The behavior of specifying multiple error pages for the same
error code is undefined; doing so is best avoided.
Code-behind is optional for both normal and error page templates. If + code-behind is not provided, TinCan will use the Page or ErrorPage + class as appropriate.
The body begins with the first line that does not start with #
and has the exact same syntax that the templates are in for this webapp.
@@ -84,5 +83,26 @@
errors, the template engine will be passed a blank line for each header
line encountered. TinCan will strip out all leading blank lines when
rendering its responses.
By default, regular pages will have a single template variable available: + page, which refers to the Page class that contains + the code-behind logic for this page. The pertinent bottle.Request + and bottle.Response objects are available to normal, non-error + pages as page.request and page.response, + respectively.
+Error pages have their code-behind logic in an ErrorPage + class. In addition to the standard page variable, error pages + also have request and error variables available by + default, which contain copies of the pertinent bottle.Request + and bottle.HTTPError objects respectively.
+The default behavior of the export method (which exports + instance variables to template variables) in both the Page and + ErrorPage classes is to export, in addition to the default + variables, every user-created instance attribute that is not callable and + whose name does not start with an underscore. This behavior can be changed + if desired by overriding that method.
+Note that if for some reason you create an instance variable named page, + it will overwrite the standard template variable by the same name.
+