The pecan.core module is the base module for creating and extending
Pecan. The core logic for processing HTTP requests and responses lives
here.
-
class pecan.core.Pecan(root, default_renderer='mako', template_path='templates', hooks=<function <lambda> at 0x43d5ed8>, custom_renderers={}, extra_template_vars={}, force_canonical=True, guess_content_type_from_ext=True, **kw)
Bases: object
Base Pecan application object. Generally created using pecan.make_app,
rather than being created manually.
Creates a Pecan application instance, which is a WSGI application.
Parameters: |
- root – A string representing a root controller object (e.g.,
“myapp.controller.root.RootController”)
- default_renderer – The default template rendering engine to use.
Defaults to mako.
- template_path – A relative file system path (from the project root)
where template files live. Defaults to ‘templates’.
- hooks – A callable which returns a list of
pecan.hooks.PecanHook
- custom_renderers – Custom renderer objects, as a dictionary keyed
by engine name.
- extra_template_vars – Any variables to inject into the template
namespace automatically.
- force_canonical – A boolean indicating if this project should
require canonical URLs.
- guess_content_type_from_ext – A boolean indicating if this project
should use the extension in the URL for guessing
the content type to return.
|
-
determine_hooks(controller=None)
Determines the hooks to be run, in which order.
Parameters: | controller – If specified, includes hooks for a specific
controller. |
-
get_args(pecan_state, all_params, remainder, argspec, im_self)
Determines the arguments for a controller based upon parameters
passed the argument specification for the controller.
-
handle_hooks(hook_type, *args)
Processes hooks of the specified type.
Parameters: |
- hook_type – The type of hook, including before, after,
on_error, and on_route.
- *args – Arguments to pass to the hooks.
|
-
handle_request(req, resp)
The main request handler for Pecan applications.
-
route(req, node, path)
Looks up a controller from a node based upon the specified path.
Parameters: |
- node – The node, such as a root controller object.
- path – The path to look up on this node.
|
-
pecan.core.abort(status_code=None, detail='', headers=None, comment=None, **kw)
Raise an HTTP status code, as specified. Useful for returning status
codes like 401 Unauthorized or 403 Forbidden.
Parameters: |
- status_code – The HTTP status code as an integer.
- detail – The message to send along, as a string.
- headers – A dictionary of headers to send along with the response.
- comment – A comment to include in the response.
|
-
pecan.core.load_app(config)
Used to load a Pecan application and its environment based on passed
configuration.
Parameters: | config – Can be a dictionary containing configuration, a string which
represents a (relative) configuration filename |
returns a pecan.Pecan object
-
pecan.core.override_template(template, content_type=None)
Call within a controller to override the template that is used in
your response.
Parameters: |
- template – a valid path to a template file, just as you would specify
in an @expose.
- content_type – a valid MIME type to use for the response.func_closure
|
-
pecan.core.redirect(location=None, internal=False, code=None, headers={}, add_slash=False)
Perform a redirect, either internal or external. An internal redirect
performs the redirect server-side, while the external redirect utilizes
an HTTP 302 status code.
Parameters: |
- location – The HTTP location to redirect to.
- internal – A boolean indicating whether the redirect should be
internal.
- code – The HTTP status code to use for the redirect. Defaults to 302.
- headers – Any HTTP headers to send with the response, as a
dictionary.
|
-
pecan.core.render(template, namespace)
Render the specified template using the Pecan rendering framework
with the specified template namespace as a dictionary. Useful in a
controller where you have no template specified in the @expose.
Parameters: |
- template – The path to your template, as you would specify in
@expose.
- namespace – The namespace to use for rendering the template, as a
dictionary.
|