flask response Content-Type
flask
中通过response
对象的headers
属性来控制header
信息。
1.控制mimetype
from flask import Flask,make_response
app = Flask(__name__)@app.route('/')
def register():rsp = make_response("test")rsp.headers['Content-Type']= 'text/xxx'return rspif __name__ == "__main__":app.run(host="0.0.0.0",port=5000,debug=True)
2.控制charset
from flask import Flask,make_response
app = Flask(__name__)@app.route('/')
def register():rsp = make_response("test")rsp.headers['Content-Type']= 'text/xxx; charset=utf-8'return rspif __name__ == "__main__":app.run(host="0.0.0.0",port=5000,debug=True)
3.通过Response
的mimetype
属性快捷控制Content-Type
。
需要注意的是mimetype
属性不能控制charset
,一般charset
会使用默认值
from flask import Flask,make_responseapp = Flask(__name__)@app.route('/')
def register():rsp = make_response("xxx")rsp.mimetype="text/xxx" # 等价于rsp.headers['Content-Type']= 'text/xxx; charset=utf-8'return rspif __name__ == "__main__":app.run(host="0.0.0.0",port=5000,debug=True)
参考:
https://flask.palletsprojects.com/en/1.1.x/api/#response-objects
https://flask.palletsprojects.com/en/1.1.x/api/#flask.Flask.make_response
https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.Headers
flask response Content-Type相关推荐
- requests的response.text 与 response.content
在某些情况下来说,response.text 与 response.content 都是来获取response中的数据信息,效果看起来差不多.那么response.text 和 response.co ...
- restTemplate http请求报错:no suitable HttpMessageConverter found for response type and content type
报错信息: org.springframework.web.client.UnknownContentTypeException: Could not extract response: no sui ...
- Error while extracting response for type [] and content type [],json返回值被解析为xml
在使用restTemplate请求restful接口时,在特定情况下总会将返回的json数据解析为xml数据然后处理,接着就会爆出标题中的错误: Error while extracting resp ...
- Error while extracting response for type [class xxx] and content type application/xml;charset=UTF-8
强烈推荐一个大神的人工智能的教程:http://www.captainbed.net/zhanghan [前言] 最近在用restTemplate进行一次http请求时发现了报错(Error whil ...
- Server returned HTTP response code 415 for URL , Content type text/plain charset=UTF-8 not support
客户端 http 请求报错 415,具体如下: Server returned HTTP response code: 415 for URL: http://ip:port/xxx 服务器端 用的是 ...
- Could not extract response: no suitable HttpMessageConverter found for content type [text/html]
目录 报错信息 源码分析 解决方法 修改 mappingJackson2HttpMessageConverter 配置 继承 mappingJackson2HttpMessageConverter 实 ...
- flask response对象
方法或属性 描述 headers 类似于字典,用来存放headers status A string with a response status. status_code The response ...
- Posted content type isn't multipart/form-data
版权声明:欢迎转载,请注明沉默王二原创. https://blog.csdn.net/qing_gee/article/details/48712507 在有文件上传的表单提交过程中,搞不好就会报Po ...
- “Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“解决方法
项目接口返回 code: 500 data: null message: "Content type 'application/x-www-form-urlencoded;charset=U ...
- feign.codec.DecodeException: Error while extracting response for type
报错信息 feign.codec.DecodeException: Error while extracting response for type [java.util.List<cn.xxx ...
最新文章
- [20180412]订阅+镜像切换
- 使用Notepad++工具查看文件的十六进制
- hdu 1166 敌兵布阵 树状数组
- 某些小时后MySql连接自动掉线
- bzoj1046(HAOI2007)上升序列
- 机器学习之类别不平衡问题 (2) —— ROC和PR曲线
- Windows域控设置 AD域策略屏蔽端口 禁用端口【全域策略生效】
- 加入百度地图遇到 framework not found BaiduMapAPI***
- 10.XSD 元素替换
- maven没有servlet(创建servlet后报错)
- 未解决:火狐浏览器提示不安全的链接
- 青龙脚本--今日头条极速版
- 常用显示器,硬盘都有哪几种接口
- 手机上好用的APP推荐
- 图片批量下载 +图片马赛克:多张图片组成端午安康!
- 报表软件选型时应该知道的
- 四元数和欧拉角优缺点
- python语言实验指导答案_Python实验指导书
- HCIA ENSP WLAN基础配置
- pyecharts源码解读(12)图表类包charts之chart模块:常用图表基类Chart、直角坐标系图表基类RectChart、3D图表基类Chart3D
热门文章
- 微课|中学生可以这样学Python(例11.2):tkinter猜数游戏(1)
- Python对象特殊方法及其用法演示
- python write函数换行_python中文件的知识点总结
- react启动命令_十分钟搭建React开发环境
- .exe已停止工作_Windows 10累积更新KB4565503和KB4565483已发布
- zabbix无效监控项_使用zabbix模板监控tomcat-解决模板部分监控项不生效问题
- php百度语音合成,Drupal 与百度云语音合成(PHP SDK)的集成
- satoshi自动上色算法_再见,老照片!百年老照片修复算法,那些高颜值的父母!...
- kendoui固定宽度_KendoUi 学习笔记(二) Grid
- http和restful知识点查阅