Python python uses the bottle Lightweight framework for Web development

Source: Internet
Author: User

The framework of current Python web development is the most popular, but this article describes a more lightweight web framework: Bottle framework. The theoretical thing is not spoken, directly on the instance code.


1. Description of the problem

Recently do a system of background development, with the python+bottle for the web background development. Provides an interface to the foreground, which provides data in JSON data format through the parameters of the foreground call interface.


2. Environmental preparedness

I am using the Linux environment, Python 2.7.x version of Python. PIP installation bottle required before using bottle, enter command: sudo pip install bottle can be installed. This has the bottle environment, you can use the bottle framework for Python web development.


3. Program Code

3.1 A Hello World program

Program Files: helloworld.py

#!/usr/bin/python#-*-conding:utf-8-*-from bottle Import *                                                          #导入bottle相关的包 @route ('/helloworld/:yourwords ', methods=[' GET ', ' POST '])                     #url接口def Hello (yourwords):                                                          return ' Hello World '. ' + yourwords                                    #返回前台数据, here Returns a string run (host= ' 0.0.0.0 ', port=8080)                                                #表示本机, interface is 8080

Open Browser, type: Http://172.16.160.122:8080/helloworld/BigData

The following page is displayed:


The red circled part of the figure is the foreground input parameter, and the page displays the returned string contents.

This completes a simple example. The bottle frame is not very lightweight.


This program is very simple, the URL yourwords is the foreground input parameters, the last returned to the data is: Hello World plus the parameters of the received string.


3.2 Instance Program code



Precautions


Python python uses the bottle Lightweight framework for Web development

Related Article

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.