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')