Python microframework Bottle

Source: Internet
Author: User

Python microframework Bottle

Currently, you need to add an activation code to the project. You are planning to write an http server separately.

Because the previous game already had an http server that generated the activation code and verification code, it was used directly.

 

Bottle is a very sophisticated WSGI framework that provides basic support for Python Web development:

URL routing,
Request/Response object encapsulation,
Template support,
Integrated with WSGI servers.


Environment:
Win7 System
Python2.7



1. Download
There is only one bottle. py file and there is no dependency outside the standard library of the task.


Test the new file useBottle. py. The content is as follows:
From bottle import route, run @ route ('/hello') # associate route/hello with the hello () def hello (): return hello World! Run (host = 'localhost', port = 8080, debug = True)

Three running results


4. A slightly more complex example
From bottle import Bottle, route, run, template, errorapp = Bottle () @ app. route ('/hello') def hello (): return hello World! @ App. route ('/') # default route @ app. route ('/hello/
 
  
') # Def greet (name = 'Stranger'): return template ('Hello {name}, how are you? ', Name = name) @ app. error (404) def error404 (error): return 'nothing here, sorry' run (app, host = 'localhost', port = 8080)
 


You can also return static files in the following format:
@route('/static/
 
  ')def server_static(filepath):    return static_file(filepath, root='/path/to/your/static/files')
 
 

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.