Bottle

http://bottlepy.org/docs/dev/
Bottle 是Python微型框架中的微型框架
一个py文件就可运行, 6行代码 打印‘hello world’

Hello world

from bottle import route, run
@route('/hello')
def hello():
    return "Hello World!"
if __name__ == '__main__':
    run(host='localhost', port=8080)


  • Routing: Requests to function-call mapping with support for clean and dynamic URLs.
  • Templates: Fast and pythonic built-in template engine and support for mako, jinja2 and cheetah templates.
  • Utilities: Convenient access to form data, file uploads, cookies, headers and other HTTP-related metadata.
  • Server: Built-in HTTP development server and support for paste, fapws3, bjoern, gae, cherrypy or any other WSGI capable HTTP server.

Dynamic Route

@route('/article/')
def article(id):
    return '

You are viewing article' + id + '

' @route('/page//') def views(id,name): return 'You are viewing the page '+ id + ' with the name of ' + name

simple login html


from bottle import route, run, template,request,post
@route('/login')
def login():
    if request.method == "GET":
        return '''
        
Username: Password:
''' @post('/login') # or @route('/login', method='POST') def do_login(): username = request.forms.get('username') password = request.forms.get('password') if username == 'parker' and password == '123': return "

Your login information was correct.

" else: return "

Login failed.

" run(host='localhost', port=8080)

你可能感兴趣的:(Bottle)