class documentation

class Bottle(object):

View In Hierarchy

Each Bottle object represents a single, distinct web application and consists of routes, callbacks, plugins, resources and configuration. Instances are callable WSGI applications.
Parameters
catchallIf true (default), handle all exceptions. Turn off to let debugging middleware handle exceptions.
Method add​_hook Attach a callback to a hook. Three hooks are currently implemented:
Method add​_route Add a route object, but do not change the Route.app attribute.
Method close Close the application and all installed plugins.
Method delete Equals route with a DELETE method parameter.
Method error Decorator: Register an output handler for a HTTP error code
Method get Equals route.
Method get​_url Return a string that matches a named route
Method hook Return a decorator that attaches a callback to a hook. See add_hook for details.
Method install Add a plugin to the list of plugins and prepare it for being applied to all routes of this application. A plugin may be a simple decorator or an object that implements the Plugin API.
Method match Search for a matching route and return a (Route , urlargs) tuple. The second value is a dictionary with parameters extracted from the URL. Raise HTTPError (404/405) on a non-match.
Method merge No summary
Method mount Mount an application (Bottle or plain WSGI) to a specific URL prefix. Example:
Method post Equals route with a POST method parameter.
Method put Equals route with a PUT method parameter.
Method remove​_hook Remove a callback from a hook.
Method reset Reset all routes (force plugins to be re-applied) and clear all caches. If an ID or route object is given, only that specific route is affected.
Method route A decorator to bind a function to a request URL. Example:
Method run Calls run with the same parameters.
Method trigger​_hook Trigger a hook and return a list of results.
Method uninstall No summary
Method wsgi The bottle WSGI-interface.
Class Variable catchall Undocumented
Instance Variable config Undocumented
Instance Variable resources Undocumented
Method __call__ Each instance of 'Bottle' is a WSGI application.
Method __init__ Undocumented
Method ​_cast No summary
Method ​_handle Undocumented
Method default​_error​_handler Undocumented
Class Variable __hook​_names Undocumented
Class Variable __hook​_reversed Undocumented
Instance Variable error​_handler Undocumented
Instance Variable plugins Undocumented
Instance Variable router Undocumented
Instance Variable routes Undocumented
Instance Variable stopped Undocumented
Property ​_hooks Undocumented
def add_hook(self, name, func):

Attach a callback to a hook. Three hooks are currently implemented:

before_request
Executed once before each request. The request context is available, but no routing has happened yet.
after_request
Executed once after each request regardless of its outcome.
app_reset
Called whenever Bottle.reset is called.
def add_route(self, route):
Add a route object, but do not change the Route.app attribute.
def close(self):
Close the application and all installed plugins.
def delete(self, path=None, method='DELETE', **options):
Equals route with a DELETE method parameter.
def error(self, code=500):
Decorator: Register an output handler for a HTTP error code
def get(self, path=None, method='GET', **options):
Equals route.
def get_url(self, routename, **kargs):
Return a string that matches a named route
def hook(self, name):
Return a decorator that attaches a callback to a hook. See add_hook for details.
def install(self, plugin):
Add a plugin to the list of plugins and prepare it for being applied to all routes of this application. A plugin may be a simple decorator or an object that implements the Plugin API.
def match(self, environ):
Search for a matching route and return a (Route , urlargs) tuple. The second value is a dictionary with parameters extracted from the URL. Raise HTTPError (404/405) on a non-match.
def merge(self, routes):
Merge the routes of another Bottle application or a list of Route objects into this application. The routes keep their 'owner', meaning that the Route.app attribute is not changed.
def mount(self, prefix, app, **options):

Mount an application (Bottle or plain WSGI) to a specific URL prefix. Example:

root_app.mount('/admin/', admin_app)

All other parameters are passed to the underlying route call.

Parameters
prefixpath prefix or mount-point. If it ends in a slash, that slash is mandatory.
appan instance of Bottle or a WSGI application.
**optionsUndocumented
def post(self, path=None, method='POST', **options):
Equals route with a POST method parameter.
def put(self, path=None, method='PUT', **options):
Equals route with a PUT method parameter.
def remove_hook(self, name, func):
Remove a callback from a hook.
def reset(self, route=None):
Reset all routes (force plugins to be re-applied) and clear all caches. If an ID or route object is given, only that specific route is affected.
def route(self, path=None, method='GET', callback=None, name=None, apply=None, skip=None, **config):

A decorator to bind a function to a request URL. Example:

@app.route('/hello/:name')
def hello(name):
    return 'Hello %s' % name

The :name part is a wildcard. See Router for syntax details.

Any additional keyword arguments are stored as route-specific configuration and passed to plugins (see Plugin.apply).

Parameters
pathRequest path or a list of paths to listen to. If no path is specified, it is automatically generated from the signature of the function.
methodHTTP method (GET, POST, PUT, ...) or a list of methods to listen to. (default: GET)
callbackAn optional shortcut to avoid the decorator syntax. route(..., callback=func) equals route(...)(func)
nameThe name for this route. (default: None)
applyA decorator or plugin or a list of plugins. These are applied to the route callback in addition to installed plugins.
skipA list of plugins, plugin classes or names. Matching plugins are not installed to this route. True skips all.
**configUndocumented
def run(self, **kwargs):
Calls run with the same parameters.
def trigger_hook(self, __name, *args, **kwargs):
Trigger a hook and return a list of results.
def uninstall(self, plugin):
Uninstall plugins. Pass an instance to remove a specific plugin, a type object to remove all plugins that match that type, a string to remove all plugins with a matching name attribute or True to remove all plugins. Return the list of removed plugins.
def wsgi(self, environ, start_response):
The bottle WSGI-interface.
catchall =

Undocumented

config =

Undocumented

resources =

Undocumented

def __call__(self, environ, start_response):
Each instance of 'Bottle' is a WSGI application.
def __init__(self, catchall=True, autojson=True):

Undocumented

def _cast(self, out, peek=None):
Try to convert the parameter into something WSGI compatible and set correct HTTP headers when possible. Support: False, str, unicode, dict, HTTPResponse, HTTPError, file-like, iterable of strings and iterable of unicodes
def _handle(self, environ):

Undocumented

def default_error_handler(self, res):

Undocumented

__hook_names: tuple[str, ...] =

Undocumented

__hook_reversed: str =

Undocumented

error_handler: dict =

Undocumented

plugins: list =

Undocumented

router =

Undocumented

routes: list =

Undocumented

stopped: bool =

Undocumented

@cached_property
_hooks =

Undocumented