restish.templating

Templating support.

class restish.templating.Rendering

Bases: object

Rendering helper class, used to generate content from templates.

args(request)
Return a dict of args that should always be present.
element(template)

Decorator that renders the returned dict of args using the template by calling render(request, template, args).

The decorated method’s first argument must be a http.Request instance. All arguments (including the request) are passed on as-is.

The decorated method must return a dict that will be passed to the render(request, template, args) function.

Parameters:
  • template – Name of the template file.
element_args(request, element)
Return a dict of args that should be present when rendering elements.
page(template, type='text/html', encoding='utf-8')

Decorator that returns an HTTP response by rendering the returned dict of args using the template by calling render(request, template, args). The response’s Content-Type header will be constructed from the type and encoding.

The decorated method’s first argument must be a http.Request instance. All arguments (including the request) are passed on as-is.

The decorated method must return a dict that will be passed to the render(request, template, args) function.

Parameters:
  • template – Name of the template file.
  • type – Optional mime type of content, defaults to ‘text/html’
  • encoding – Optional encoding of output, default to ‘utf-8’.
page_args(request, page)
Return a dict of args that should be present when rendering pages.
render(request, template, args={}, encoding=None)

Render the template and args using the configured templating engine.

Parameters:
  • request – Request instance.
  • template – Name of the template file.
  • args – Dictionary of args to pass to the template renderer.
  • encoding – Optional output encoding, defaults to None, i.e. output will be unicode (or unicode-safe).

This Page

Quick search