View Variables

Keystone makes several objects and functions available within Views as global variables — that is, they need not be declared, they are simply available to your Python and template code.

request

class Request

A Werkzeug Request instance, available in views as request. The Werkzeug documentation contains a more comlete list of available attributes.

method

HTTP method name

cookies

HTTP cookies, as an ImmutableTypeConversionDict

args

HTTP GET parameters (query string), as an ImmutableMultiDict

form

HTTP POST parameters, as an ImmutableMultiDict

values

Union of args and form.

headers

The actual Response instance is not constructed until after a view’s Python code executes, but aspects of it can be controlled through several View Variables:

class Headers

A Werkzeug Headers instance, available in views as headers. The Werkzeug documentation contains a more comlete list of available attributes and methods.

add(key, value, **kw)

Add the value to the header named key. Keyword arguments can be used to specify additional parameters for the header:

headers.add('Content-Type', 'text/plain')
headers.add('Content-Disposition', 'attachment', filename='blah.txt')
set(key, value, **kw)

Similar to add(), but overwrites any previously set values for headers which accept multiple values.

get(key, default=None, type=None)

Get the value of the header named key, or the default value if no such header is set. Optionally convert using type (a callable of one argument).

has_key(key)

Return True if the header named key exists, False otherwise.

return_response

return_response(body)

Bypass template rendering and immediately return the given body. body may be any iterable object or string.

http

The http view variable is a module which contains subclasses of HTTPException for returning non-200-status HTTP responses. Full documentation on the exceptions is available at http Module.

app_dir

app_dir

The full, absolute path to the root of the Keystone application directory.

Table Of Contents

Previous topic

Keystone Quickstart

Next topic

Advanced Topics

This Page