Bottle is a micro framework designed for prototyping and building small web applications and services. It stays out of your way and allows you to get things done fast, but misses some advanced features and ready-to-use solutions found in other frameworks (MVC, ORM, form validation, scaffolding, XML-RPC). Although it is possible to add these features and build complex applications with Bottle, you should consider using a full-stack Web framework like pylons or paste instead.
Bottle searches in
./views/ for templates. In a mod_python or mod_wsgi environment, the working directory (
./) depends on your Apache settings. You should add an absolute path to the template search path:
so bottle searches the right paths.
In dynamic route syntax, a placeholder token (
:name) matches everything up to the next slash. This equals to
[^/]+ in regular expression syntax. To accept slashes too, you have to add a custom regular pattern to the placeholder. An example:
/images/:filepath#.*# would match
Redirects and url-building only works if bottle knows the public address and location of your application. If you run bottle locally behind a reverse proxy or load balancer, some information might get lost along the way. For example, the
wsgi.url_scheme value or the
Host header might reflect the local request by your proxy, not the real request by the client. Here is a small WSGI middleware snippet that helps to fix these values:
def fix_environ_middleware(app): def fixed_app(environ, start_response): environ['wsgi.url_scheme'] = 'https' environ['HTTP_X_FORWARDED_HOST'] = 'example.com' return app(environ, start_response) return https_app app = bottle.default_app() app.wsgi = fix_environ_middleware(app.wsgi)
© 2009–2017 Marcel Hellkamp
Licensed under the MIT License.