summaryrefslogtreecommitdiff
path: root/plugins/werkzeug/README
blob: 5f11552e4e075068ff400aee35e27bf9ea574f54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
=====================
Bottle-Werkzeug
=====================

`Werkzeug <http://werkzeug.pocoo.org/>`_ is a powerful WSGI utility library for 
Python. It includes an interactive debugger and feature-packed request and response 
objects.

This plugin integrates :class:`werkzeug.wrappers.Request` and
:class:`werkzeug.wrappers.Response` as an alternative to the built-in
implementations, adds support for :mod:`werkzeug.exceptions` and replaces the
default error page with an interactive debugger.



Installation
===============

Install with one of the following commands::

    $ pip install bottle-werkzeug
    $ easy_install bottle-werkzeug

or download the latest version from github::

    $ git clone git://github.com/defnull/bottle.git
    $ cd bottle/plugins/werkzeug
    $ python setup.py install



Usage
===============

Once installed to an application, this plugin adds support for 
:class:`werkzeug.wrappers.Response`, all kinds of :mod:`werkzeug.exceptions` and
provides a thread-local instance of :class:`werkzeug.wrappers.Request` that is
updated with each request. The plugin instance itself doubles as a werkzeug
module object, so you don't have to import werkzeug in your application. Here
is an example::

    import bottle
    from bottle.ext import werkzeug

    app = bottle.Bottle()
    werkzeug = werkzeug.Plugin()
    app.install(werkzeug)

    req = werkzeug.request # For the lazy.

    @app.route('/hello/:name')
    def say_hello(name):
        greet = {'en':'Hello', 'de':'Hallo', 'fr':'Bonjour'}
        language = req.accept_languages.best_match(greet.keys())
        if language:
            return werkzeug.Response('%s %s!' % (greet[language], name))
        else:
            raise werkzeug.exceptions.NotAcceptable()



Using the Debugger
====================

This plugin replaces the default error page with an advanced debugger. If you
have the `evalex` feature enabled, you will get an interactive console that
allows you to inspect the error context in the browser. Please read
`Debugging Applications with werkzeug <werkzeug:debug>`_ before you enable this
feature.



Configuration
=============

The following configuration options exist for the plugin class:

* **evalex**: Enable the exception evaluation feature (interactive debugging). This requires a non-forking server and is a security risk. Please read `Debugging Applications with werkzeug <werkzeug:debug>`_. (default: False)
* **request_class**: Defaults to :class:`werkzeug.wrappers.Request`
* **debugger_class**: Defaults to a subclass of :class:`werkzeug.debug.DebuggedApplication` which obeys the :data:`bottle.DEBUG` setting.