Router / URL Mapping

The core system of the bottle.py micro Web-Framework is the router, which allows a dynamically mapping of URLs to the corresponding functions using existing or own filters, or regular expressions.

The required function to handle this is called route and can be called both as a decorator above the respective function (as you can see on the example on the right) or as a normal function.

You can find more information in our documentation

from bottle import route, run, template

@route('/')
def index(name):
    return template('Home Sweet Home!')

@route('/hello/<name>')
def index(name):
    return template('<b>Hello {{name}}</b>!', name=name)

run(host='localhost', port=8080)

SimpleTemplate Engine

Creating templates for showing dynamic content can be very easy using the onboard SimpleTemplate Engine. It allows you to include plain Python Source Code in a single-line as well as a multi-line way.

from bottle import route, run, view

@route('/hello/<name>')       # Set the URL Path
@view('template.html')        # Set the HTML File
def index(name):
    return dict(name=name);

run(host='localhost', port=8080)
<%
# The content between the <% / %> Tags gets
# ... interpreted as Python Source Code 
from random import random
number = str( int( random() * 100 ) )
%>
<p><big>Hello {{name.capitalize()}}!</big></p>
<ul>
    % # Prefix a Single-Line Python Code with a %
    % for item in ["One", "Two", "Three"]:
        <li>{{item}}</li>
    % end
</ul>
<p>Here is a random number: {{number}}.</p>
https://localhost:8080/hallo/world

Hello World!

  • One
  • Two
  • Three

Here is a random number: 10.

Tools & Utilities

Form and Request Data

You can access the form and request data via various application interfaces, which allows you to process and also integrate them into your HTML template.

Lean More

File-Upload Handler

An additional class handler manages and allows the processing of file uploads, which are sent to your Python backend via the corresponding form fields.

Lean More

Cookies

To place, read and delete cookies you can easily use an additional helper class. Signed Cookies to prevent the known forgery methods are also easily possible.

Lean More

Error-Handling

Thanks to the sophisticated error handling, you will be informed immediately about invalid code. You can also set up your own error pages to format the output accordingly.

Lean More

HTTP Header

The HTTP header and meta information can be directly read out and processed within the routing functions. It is as easy as sending data back to the browser.

Lean More

Plugins

The environment of bottle.py can be completely expanded and optimized with additional plugins and systems for your own intended use.

View all Plugins

Get bottle.py

Latest Stable Version

sudo pip install bottle sudo easy_install bottle sudo apt-get install python-bottle

Latest Development Version

wget http://bottlepy.org/bottle.py

Direct Download