flask 文件下载 文件服务器 请求参数 函数修饰符
180M电子书
通过已经下载到pc,在上传到私有公网服务器,之后,再异地下载
以下代码,文件内容错乱
[root@bigdata-server- mydataweb]# tree
.
├── mydl.py
└── templates
├── hello.html
└── 计算机网络第六版.pdf directory, files
[root@bigdata-server- mydataweb]# cat mydl.py
from flask import Flask, render_template myapp = Flask(__name__) @myapp.route('/hello/<name>')
def hello(name=None):
return render_template('hello.html', name=name) if __name__ == '__main__':
myapp.run(host='0.0.0.0', debug=True)
[root@bigdata-server- mydataweb]# cat templates/hello.html
<!doctype html>
<title>Hello from Flask</title>
{% if name %}
<h1>Hello {{ name }}!</h1>
{% else %}
<h1>Hello, World!</h1>
{% endif %} <a href="./计算机网络第六版.pdf" download="计算机网络第六版.pdf">Download file</a>
[root@bigdata-server- mydataweb]#
[root@bigdata-server-03 mydataweb]# du -Bm
87M ./templates
87M .
[root@bigdata-server-03 mydataweb]# du -Bm
87M ./templates
87M .
[root@bigdata-server-03 mydataweb]# du -Bk
89288K ./templates
89296K .
[root@bigdata-server-03 mydataweb]# du -Bk
89464K ./templates
89472K .
[root@bigdata-server-03 mydataweb]#
sftp

浏览器显示的文件地址为
http://ip:5000/hello/file
局域网测试时: http://192.168.2.51:5000/hello/a.txt
待优化方向:
在不要求公网ip的情况下,走局域网快速传输到手机
以下代码,测试了4K txt文件
from flask import Flask, send_from_directory
myapp = Flask(__name__)
@myapp.route('/hello/<name>')
def hello(name=None):
if name == 'cisco':
return send_from_directory('./', 'f.txt', as_attachment=True)
if __name__ == '__main__':
myapp.run(host='0.0.0.0', debug=True)
180M pdf文件未测试
服务脚本
from flask import Flask, send_from_directory
myapp = Flask(__name__)
@myapp.route('/myfile/<uid>')
def myfile(uid=None):
f = '{}logo.jpg'.format(uid)
return send_from_directory('./myfile/', f, as_attachment=True)
@myapp.route('/mycode/<imgname>')
def mycode(imgname=None):
f = imgname
return send_from_directory('./mycode/', f, as_attachment=True)
if __name__ == '__main__':
myapp.run(host='0.0.0.0', debug=True)
文件下载
import requests url = 'http://192.168.6.22:5000/hello/cisco'
url = 'http://192.168.6.22:5000/myfile/34054505' def dl_webimg(img_path, img_url, img_name):
try:
# ONLY
if requests.get(img_url).status_code == :
bytes = requests.get(img_url)._content
if bytes != :
r = '{}{}'.format(img_path, img_name)
with open(r, 'wb')as f:
f.write(bytes)
return True
except Exception as e:
logs = e
print(logs)
return False
192.168.3.103 - - [16/May/2018 19:38:44] "GET /myfile/34062376 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:38:49] "GET /myfile/50011457 HTTP/1.1" 404 -
192.168.2.157 - - [16/May/2018 19:38:54] "GET /myfile/50008187 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:38:54] "GET /myfile/50008187 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:39:32] "GET /myfile/50004237 HTTP/1.1" 404 -
192.168.3.103 - - [16/May/2018 19:40:36] "GET /myfile/50005924 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:40:36] "GET /myfile/50005924 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:40:39] "GET /myfile/50011844 HTTP/1.1" 404 -
192.168.3.103 - - [16/May/2018 19:41:23] "GET /myfile/33999180 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:41:23] "GET /myfile/33999180 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:41:27] "GET /myfile/33985565 HTTP/1.1" 404 -
192.168.2.157 - - [16/May/2018 19:41:28] "GET /myfile/50006768 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:41:28] "GET /myfile/50006768 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:41:31] "GET /myfile/50012105 HTTP/1.1" 404 -
192.168.3.102 - - [16/May/2018 19:41:48] "GET /myfile/34059578 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:41:48] "GET /myfile/34059578 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:41:56] "GET /myfile/50011842 HTTP/1.1" 404 -
192.168.3.102 - - [16/May/2018 19:41:57] "GET /myfile/50011596 HTTP/1.1" 404 -
192.168.2.40 - - [16/May/2018 19:42:26] "GET /myfile/34046392 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:42:26] "GET /myfile/34046392 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:42:40] "GET /myfile/50010681 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:42:40] "GET /myfile/50010681 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:42:40] "GET /myfile/34005188 HTTP/1.1" 404 -
192.168.2.40 - - [16/May/2018 19:42:42] "GET /myfile/50009318 HTTP/1.1" 404 -
192.168.3.102 - - [16/May/2018 19:42:49] "GET /myfile/34057076 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:42:49] "GET /myfile/34057076 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:42:57] "GET /myfile/50010796 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:42:57] "GET /myfile/50010796 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:42:57] "GET /myfile/50011625 HTTP/1.1" 404 -
192.168.2.157 - - [16/May/2018 19:43:05] "GET /myfile/34064430 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:43:05] "GET /myfile/34064430 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:43:07] "GET /myfile/34034844 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:43:07] "GET /myfile/34034844 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:43:11] "GET /myfile/33996397 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:43:11] "GET /myfile/33996397 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:43:20] "GET /myfile/50011577 HTTP/1.1" 404 -
192.168.2.40 - - [16/May/2018 19:43:25] "GET /myfile/50006165 HTTP/1.1" 404 -
192.168.3.103 - - [16/May/2018 19:43:56] "GET /myfile/34061589 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:43:56] "GET /myfile/34061589 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:44:03] "GET /myfile/34015391 HTTP/1.1" 404 -
192.168.3.103 - - [16/May/2018 19:44:07] "GET /myfile/50007988 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:44:07] "GET /myfile/50007988 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:44:10] "GET /myfile/50001587 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:44:10] "GET /myfile/50001587 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:44:14] "GET /myfile/50005155 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:44:14] "GET /myfile/50005155 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:44:19] "GET /myfile/50010215 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:44:20] "GET /myfile/50010215 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:44:23] "GET /myfile/50005051 HTTP/1.1" 404 -
192.168.3.103 - - [16/May/2018 19:44:27] "GET /myfile/50011528 HTTP/1.1" 404 -
192.168.2.40 - - [16/May/2018 19:44:43] "GET /myfile/34031512 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:44:43] "GET /myfile/34031512 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:44:52] "GET /myfile/50002485 HTTP/1.1" 404 -
192.168.2.157 - - [16/May/2018 19:44:55] "GET /myfile/50000148 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:44:55] "GET /myfile/50000148 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:44:57] "GET /myfile/34015601 HTTP/1.1" 404 -
192.168.3.102 - - [16/May/2018 19:45:02] "GET /myfile/34030027 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:02] "GET /myfile/34030027 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:45:05] "GET /myfile/50009356 HTTP/1.1" 404 -
192.168.3.102 - - [16/May/2018 19:45:12] "GET /myfile/34064430 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:12] "GET /myfile/34064430 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:19] "GET /myfile/50007083 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:19] "GET /myfile/50007083 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:22] "GET /myfile/50009027 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:22] "GET /myfile/50009027 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:27] "GET /myfile/34021924 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:27] "GET /myfile/34021924 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:31] "GET /myfile/50003822 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:31] "GET /myfile/50003822 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:38] "GET /myfile/50007274 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:38] "GET /myfile/50007274 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:45:41] "GET /myfile/34064093 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:45:41] "GET /myfile/34064093 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:41] "GET /myfile/34063466 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:41] "GET /myfile/34063466 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:45:45] "GET /myfile/50007149 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:45:45] "GET /myfile/50007149 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:48] "GET /myfile/34004441 HTTP/1.1" 404 -
192.168.3.103 - - [16/May/2018 19:45:51] "GET /myfile/34063434 HTTP/1.1" 200 -
flask笔记:14:获取所有post或者get请求参数 - CSDN博客 https://blog.csdn.net/u013055678/article/details/70214756
函数修饰符
python中的@ - 半天的半天 - 博客园 https://www.cnblogs.com/mxh1099/p/5685619.html
flask 文件下载 文件服务器 请求参数 函数修饰符的更多相关文章
- Python中的函数修饰符@
首先,什么是函数修饰符?函数修饰符就是对原有函数做一层包装.比如有以下两个函数: 复制代码 def func1(): print 'I am function func1' def func2(): ...
- python函数修饰符@的使用
python函数修饰符@的作用是为现有函数增加额外的功能,常用于插入日志.性能测试.事务处理等等. 创建函数修饰符的规则:(1)修饰符是一个函数(2)修饰符取被修饰函数为参数(3)修饰符返回一个新函数 ...
- Python 函数修饰符(装饰器)的使用
Python 函数修饰符(装饰器)的使用 1. 修饰符的来源修饰符是一个很著名的设计模式,经常被用于有切面需求的场景,较为经典的有插入日志.性能测试.事务处理等. 修饰符是解决这类问题的绝佳设计, ...
- solidity 学习笔记(3) 函数修饰符/继承
修饰符: 函数修饰符有 constant view pure 其中 constant和view的功能是一样的 不会消耗gas 也就是说不会做任何存储 constant在5.0以后的版本中被废弃 ...
- Flask基础(09)-->请求勾子函数
什么是请求勾子? 为了让每个视图函数避免编写重复的功能代码,flask提供了通用设施的功能,就是所谓的勾子 那么请求勾子就是,在浏览器请求服务器资源的前后挂载相关的处理函数 请求勾子有什么作用? 作用 ...
- (三)flask中的请求钩子函数
请求勾子 在客户端和服务器交互的过程中,有些准备工作或扫尾工作需要处理,比如: 在请求开始时,建立数据库连接: 在请求开始时,根据需求进行权限校验: 在请求结束时,指定数据的交互格式: 为了让每个视图 ...
- ethereum(以太坊)(十)--函数修饰符
pragma solidity ^0.4.0; contract modifierTest{ uint public v1; uint constant v2 =10; //uint constant ...
- Java中的public、private、protected,函数修饰符
1.public:public表明该数据成员.成员函数是对所有用户开放的,项目中其他脚本都可以直接进行调用 2.private:private表示私有,私有的意思就是除了脚本之外,项目中其他类都不可以 ...
- Python 中的@修饰符作用
在Python 2.4以上的的函数中偶尔会看到函数定义的上一行有@functionName的修饰,这一下这个语法细节,其实这有点像C语言带参数的宏操作,解释器读到这样的修饰之后,会先解析@后的内容,直 ...
随机推荐
- python基础003
1. list 1.1 基础 list是一组有序的集合序列,可以包含任何类型且不必相同,并支持嵌套.采用如下创建方式: li = ["spam",2.0,5,[10,20]] 列表 ...
- 【实验吧】转瞬即逝write up
---恢复内容开始--- 虽然这是很简单的一道题,但这是我第一次拿着题有很清晰的思路,并且脚本也有思路写,拿到文件用ida打开,分析main函数: int __cdecl main(int argc, ...
- 大数据学习——flume日志分类采集汇总
1. 案例场景 A.B两台日志服务机器实时生产日志主要类型为access.log.nginx.log.web.log 现在要求: 把A.B 机器中的access.log.nginx.log.web.l ...
- jmeter给cookie设置sessionId避免其他脚本多次登录
1.相关知识: http头部可以设置:浏览器显示内容类型,如content-type:text/html http头部可以存放:浏览器的cookie信息——cookie是对用户身份进行判断的内容 ht ...
- [luoguP3068] [USACO13JAN]派对邀请函Party Invitations(stl大乱交)
传送门 记录每一个编号在那些组中,可以用vector,这里选择链式前向星. 每一组用set 将被邀请的放到queue中 #include <set> #include <queue& ...
- Scrapy的log日志功能
Logging Scrapy提供了log功能,可以通过 logging 模块使用 可以修改配置文件settings.py,任意位置添加下面两行 LOG_FILE = "mySpider.lo ...
- PatentTips - Wear Leveling for Erasable Memories
BACKGROUND Erasable memories may have erasable elements that can become unreliable after a predeterm ...
- Free Web Application Firewall相关资料
http://www.freewaf.org/solution/#1 http://baike.soso.com/v60659982.htm
- 进程Queue、线程Queue、堆栈、生产者消费者模型
没学队列之前,可以用文件实现进程之间通信 但是有2个问题: 1. 速度慢:文件是保存在硬盘空间 2. 为了数据安全要加锁(处理锁是一件很麻烦的事,容易死锁,建议自己轻易不要处理锁) 队列:队列是基于管 ...
- django学习之- 动态验证码学习
实例:通过前台和后台,实现用户登录页面动态图片验证码校验,图片验证码部分使用Pillow模块实现,作为单独学习部分记录. 前端: <!DOCTYPE html> <html lang ...