python 练习

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值