Bottle: Python Web Framework


Hits: 508  

I really like Bottle: Python Web Framework. Bottle is very simple, fast and powerful Python micro-framework. It is perfect for small web applications and rapid prototyping where you need simple/small API server.

Bottle is a fast, simple and lightweight WSGI micro web-framework for Python.

Installation

Install Bottle with pip install bottle or download the source package at PyPI.

Download and Install

Install the latest stable release (Bottle runs with Python 2.7 and 3.3+.)

#pip install bottle

Or

#easy_install -U bottle

Or

download bottle.py (unstable) into your project directory.

– app.py
– bottle.py

Example: “Hello World” (app.py)

from bottle import route, run

@route(‘/hello/:name’)
def index(name=’World’):
return ‘Hello %s!‘ % name

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

Bottle Python

Point your browser to http://localhost:8080/hello/sandeep

Links

https://github.com/bottlepy/bottle
https://raw.githubusercontent.com/bottlepy/bottle/master/bottle.py

Below find simple routing, template, static CDN, Ajax, redirect functions

Test URL for above bottle python code run on port 7800

# python bottle_example.py

http://localhost:7800/
http://localhost:7800/hello
http://localhost:7800/ajax
http://localhost:7800/redirect
http://localhost:7800/404
http://localhost:7800/upload
http://localhost:7800/tpl (“test” is text file on [Web-App-Root])
http://localhost:7800/static/god.jpg (“god.jpg” saved on [Web-App-Root])