pecan.decorators – Pecan Decorators

The pecan.decorators module includes useful decorators for creating Pecan applications.

pecan.decorators.accept_noncanonical(func)

Flags a controller method as accepting non-canoncial URLs.

pecan.decorators.after_commit(action)

If utilizing the pecan.hooks TransactionHook, allows you to flag a controller method to perform a callable action after the commit is successfully issued.

Parameters

action – The callable to call after the commit is successfully issued.

pecan.decorators.after_rollback(action)

If utilizing the pecan.hooks TransactionHook, allows you to flag a controller method to perform a callable action after the rollback is successfully issued.

Parameters

action – The callable to call after the rollback is successfully issued.

pecan.decorators.expose(template=None, generic=False, route=None, **kw)

Decorator used to flag controller methods as being “exposed” for access via HTTP, and to configure that access.

Parameters
  • template – The path to a template, relative to the base template directory. Can also be passed a string representing a special or custom renderer, such as 'json' for The JSON Renderer.

  • content_type – The content-type to use for this template.

  • generic – A boolean which flags this as a “generic” controller, which uses generic functions based upon functools.singledispatch generic functions. Allows you to split a single controller into multiple paths based upon HTTP method.

  • route – The name of the path segment to match (excluding separator characters, like /). Defaults to the name of the function itself, but this can be used to resolve paths which are not valid Python function names, e.g., if you wanted to route a function to `some-special-path’.

pecan.decorators.transactional(ignore_redirects=True)

If utilizing the pecan.hooks TransactionHook, allows you to flag a controller method or class as being wrapped in a transaction, regardless of HTTP method.

Parameters

ignore_redirects – Indicates if the hook should ignore redirects for this controller or not.