from flask import Flask, request
from werkzeug.datastructures import FileStorage app = Flask(__name__) @app.route('/', methods=['get', 'post'])
def index():
# 获取请求的基础数据
# print(request.url) # 请求的URL
# print(request.method) # 本次请求的请求方式
# print(request.headers) # 获取请求头信息 类字典对象 # print(request.headers['Host'])
# print(request.headers.get('Host')) # 建议使用get方法, 键不存在不报错 # 请求传递数据 1> URL路径 -> 路由变量 2> 查询字符串 get 3> 请求体 post 4> 请求头 -> request.headers # 获取查询字符串 -> request.args xx?name=zs&age=20 类字典对象
# print(request.args.get('name'))
# print(request.args.get('age')) # 请求体: 键值对(表单) 文本(json/xml) 文件(图片/音频) # 获取post键值对 -> request.form 类字典对象
# print(request.form.get('username')) # 获取post文本数据 -> request.data / request.json
# print(request.data) # 返回bytes类型
# print(request.json.get('age')) # request.json直接将json字符串转为字典 # 获取post文件 -> request.files 类字典对象
file = request.files.get("avatar") # type: FileStorage
# print(type(file)) # 返回 FileStorage文件对象
# 将文件保存到本地
file.save('123.jpg') # 获取文件的二进制数据
# img_bytes = file.read()
# print(img_bytes) return "index" if __name__ == '__main__':
app.run(debug=True)

最新文章

  1. 【Java EE 学习 78 中】【数据采集系统第十天】【Spring远程调用】
  2. Android按需添加Google Play服务
  3. Union函数
  4. Scala Collection简介
  5. 【MVC】ASP.NET MVC中实现多个按钮提交的几种方法
  6. xcode不能连接svn以及不能导入的解决方法
  7. 你的数据根本不够大,别老扯什么Hadoop了
  8. [原博客] POI系列(3)
  9. Makefile常用调试方法
  10. [LeetCode] Sliding Window Median 滑动窗口中位数
  11. seo优化做起来不是哪么简单,其实需要的是思维
  12. 微信小程序onLaunch、onLoad执行生命周期
  13. 09-Python入门学习-函数基础与参数
  14. HDU2138(Miller-Rabin素数检测)
  15. 北航OO第二单元总结
  16. Codeforces1097D. Makoto and a Blackboard(数论+dp+概率期望)
  17. 补充:pyhton 2 和3中的beyts类型
  18. 在 Django/Flask 开发服务器上使用 HTTPS
  19. jQuery 作业三个按钮
  20. NET Core 1.1 版本项目和2.0环境下的项目开发注意事项

热门文章

  1. Jmeter:随机类函数
  2. Vue 双向绑定
  3. The first python article
  4. centos7下的apache2.4安全配置
  5. mysql redis 开启远程访问
  6. Beginning IOS 7 Development Exploring the IOS SDK - Navigation Controllers and Table Views
  7. js 判断gps是否超出设定范围
  8. Security Bulletin: IBM WebSphere Application Server is vulnerable to a remote code execution vulnerability (CVE-2023-23477)
  9. 配置PostMan以访问、连接D365 / Dataverse环境
  10. zabbix源码目录结构