赞
踩
本节我们一起来学习bottle web框架加载页面文件,在浏览器打开一个图片或者pdf文件。
** 文件打开后的效果**
具体代码操作:
from bottle import run, route, request, static_file
@route('/', method=['GET', 'POST'])
def test():
# 第一个参数是文件名,第二个参数是文件绝对路径,第三个参数是定义内容类型头,第四个参数是决定文件打开或者是下载,最后一个参数是决定文件的编码方式
return static_file('Python金融大数据分析.pdf', r'C:\Users\Administrator\Desktop\bottle框架研究', mimetype='auto', download=False, charset='UTF-8')
run(host='127.0.0.1', port=80, server='twisted', debug=True)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。