Python uses the Bottle framework for Web development

Source: Internet
Author: User
This article mainly introduces Python's use of the Bottle lightweight framework for Web development. if you need it, you can refer to the current Python Web development framework to calculate Django as the most popular one, however, this article introduces a lightweight Web framework: the Bottle framework. Let's stop talking about the theoretical things and go directly to the instance code.

1. problem description
Recently, we developed a system in the background, using Python + Bottle for web background development. Provide an interface for the front-end to provide Json data format data through parameters when the front-end calls the interface.

2. prepare the environment
I am using a Linux environment, python 2.7.x. Run the command: sudo pip install Bottle to install bottle. In this way, you can use the Bottle framework for Python Web development.

3. program code
3.1 A Hello World program
Program File: helloworld. py

#! /Usr/bin/python #-*-conding: UTF-8-*-from bottle import * # import a bottle-Related Package @ route ('/helloworld/: yourword ', methods = ['GET', 'post']) # url interface. pay attention to the parameter writing format. the preceding colon indicates that the parameter def hello (yourwords): return 'Hello world. '+ yourwords # return foreground data. here, a string run (host = '0. 0.0.0 ', port = 8080) # indicates the local machine and the interface is 8080

Run python helloworld. py
Open your browser and enter: http: // 172.16.160.122: 8080/helloworld/BigData. you just need to change the IP address to your own address.
The following page is displayed:

For more articles about using the Bottle framework for Web development in Python, refer to the PHP Chinese website!

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.