python Web 框架bottle超清晰使用范例,pythonbottle,#coding: utf
文章由Byrx.net分享于2019-03-23 09:03:21
python Web 框架bottle超清晰使用范例,pythonbottle,#coding: utf
#coding: utf-8from bottle import route, error, post, get, run, static_file, abort, redirect, response, request, template@route('/')@route('/index.html')def index(): return '<a href="/hello">Go to Hello World page</a>'@route('/hello')def hello(): return '<h1>HELLO WOLRD</h1>'@route('/hello/:name')def hello_name(name): page = request.GET.get('page', '1') return '<h1>HELLO %s <br/>(%s)</h1>' % (name, page)@route('/static/:filename')def serve_static(filename): return static_file(filename, root='/home/arthur/workspace/my_python_codes/src/')@route('/raise_error')def raise_error(): abort(404, "error...")@route('/redirect')def redirect_to_hello(): redirect('/hello')@route('/ajax')def ajax_response(): return {'dictionary': 'you will see ajax response right? Content-Type will be "application/json"'}@error(404)def error404(error): return '404 error !!!!!'@get('/upload')def upload_view(): return """ <form action="/upload" method="post" enctype="multipart/form-data"> <input type="text" name="name" /> <input type="file" name="data" /> <input type="submit" name="submit" value="upload now" /> </form> """ @post('/upload')def do_upload(): name = request.forms.get('name') data = request.files.get('data') if name is not None and data is not None: raw = data.file.read() # small files =.= filename = data.filename return "Hello %s! You uploaded %s (%d bytes)." % (name, filename, len(raw)) return "You missed a field."@route('/tpl')def tpl(): return template('test')run(host='localhost', port=8000, reloader=True)
相关内容
- 一个Python的交互式解释器,python解释器,因为在安卓上装
- 用python正则表达式提取网页的url,python正则表达式,im
- 获取上一个月最后一天的日期,获取最后一天日期,[P
- 获取上一个月第一天的日期,获取第一天日期,[Python]代
- 用python3抓取中文网页,python3中文网页,用python3抓取中文
- 嵌套的dict按对象方式操作,嵌套dict对象,[Python]代码c
- python科学计算,,python科学计算fr
- 使用Python访问并下载网页内容,python访问网页内容,[P
- 多线程下载百度图片大图,多线程百度图片大图,App.p
- 使用Python访问并下载网页内容,python访问网页内容,[P
评论关闭