Python bottle Framework
Bottle is a fast, concise, lightweight, wsig-based, mini-web framework that consists of only one. py file, which does not rely on any other modules, except for Python's standard library.
The bottle framework can be broadly divided into the following sections:
Routing system that handles different requests to the specified function
Template system that renders special syntax in a template as a string, it is worth saying that the bottle template engine can be arbitrarily specified: Bottle built-in templates, Mako, JINJA2, Cheetah
A public component that provides information related to processing requests, such as: form data, cookies, request-first
Services, bottle supports multiple WSGI-based services by default
Pip Install bottle
Easy_install bottle
Framework basic Use, example:
#!/usr/bin/env python#-*-coding:utf-8-*-from bottle Import bottleroot = Bottle () @root. Route ('/index/') def index ():
return "Hello World" root.run (host= ' localhost ', port=8080)
Effect:
First, the routing system
The routing system is the URL corresponding to the specified function, when the user requests a URL, the specified function to handle the current request, for the bottle routing system can be divided into several categories:
Static routes
Dynamic routing, regular expressions
Request method Routing, POST, GET, put, etc.
Secondary routing, distributed to other portals
1. Static routing
@root. Route ('/index/') def index (): return "Welcome index page"
2. Dynamic routing
Enter the URL and parameters
@root. Route ('/index/<pagename> ') def index (PAGENAME): return pagename
The input parameter is a number
@root. Route ('/index/<id:int> ') def index (ID): return str (ID)
Python bottle Framework