Python bottle Framework

Source: Internet
Author: User

Python bottle Framework

    • Brief introduction:

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

    • Installation

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.