from bottle import route,run,template,view,static_file
@route('/hello')
def hello():
return template('hello')
@route('/hello2')
def hell2():
name_="刘洋"
age_="38"
weight_="158"
blog_="www.liuyang.com"
return template('hello_temp2',name=name_,age=age_,weight=weight_,blog=blog_)
@route('/hello3')
@view('hello_temp3')
def hell3():
name_="王岩"
age_="38"
weight_="138"
blog_="www.wangyan.com"
info_={'name':name_,'age':age_,'weight':weight_,'blog':blog_}
return info_
@route('/hello4')
@view('hello_temp4')
def hell3():
name_="刘强"
myfriend_=['赵义强','中龙宝','刘亦菲']
myinfo_={'age':38,'weight':184}
blog_="www.liuqiang.com"
info_={'name':name_,'age':myinfo_,'weight':myinfo_,'blog':blog_,'SNS':myfriend_}
return info_
@route('/download/<filename>')
def download(filename):
return static_file(filename,"e:\\python",download=True)
run(host='0.0.0.0',port=8090,debug=True)
from bottle import run,request,route,template,static_file
@route('/')
def 首页():
return static_file('index.html','e:\python')
@route('/img/<file>')
def 首页(file):
return static_file('file.jpg','e:\python')
@route('/img/<filepath:path>')
def 首页(filepath):
return static_file('filepath','e:\\python')
run(hostname='0.0.0.0',port=8090)
[root@localhost python]# cat main.py
import sys
import os
import bottle
from bottle import run,request,route,template,static_file
@route("/")
def index():
return 'hello world'
@route('/hello/:name')
def index1(name='world1111'):
return 'Hello {}!' .format(name)
@route('/object/:id#[0-9]+#')
def view_object(id):
return 'Object ID: {}'.format(id)
@route('/ABC/:name')
def abc(name):
return 'My name is {}'.format(name)
@route('/static/<filename>')
def do_download(filename):
return static_file(filename,root="/tmp",download=True)
@route('/upload/<savename>', method='POST')
def do_upload(savename):
upload = request.files.get('filename')
save_path = os.path.join('/tmp', savename)
upload.save(save_path)
return 'OK'
def main():
run(host = '0.0.0.0',port = 9080, debug = True, reloader = True)
if __name__ =="__main__":
sys.exit(main())