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.通过Responsemimetype属性快捷控制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相关推荐

  1. requests的response.text 与 response.content

    在某些情况下来说,response.text 与 response.content 都是来获取response中的数据信息,效果看起来差不多.那么response.text 和 response.co ...

  2. restTemplate http请求报错:no suitable HttpMessageConverter found for response type and content type

    报错信息: org.springframework.web.client.UnknownContentTypeException: Could not extract response: no sui ...

  3. Error while extracting response for type [] and content type [],json返回值被解析为xml

    在使用restTemplate请求restful接口时,在特定情况下总会将返回的json数据解析为xml数据然后处理,接着就会爆出标题中的错误: Error while extracting resp ...

  4. 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 ...

  5. 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 服务器端 用的是 ...

  6. Could not extract response: no suitable HttpMessageConverter found for content type [text/html]

    目录 报错信息 源码分析 解决方法 修改 mappingJackson2HttpMessageConverter 配置 继承 mappingJackson2HttpMessageConverter 实 ...

  7. flask response对象

    方法或属性 描述 headers 类似于字典,用来存放headers status A string with a response status. status_code The response ...

  8. Posted content type isn't multipart/form-data

    版权声明:欢迎转载,请注明沉默王二原创. https://blog.csdn.net/qing_gee/article/details/48712507 在有文件上传的表单提交过程中,搞不好就会报Po ...

  9. “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 ...

  10. feign.codec.DecodeException: Error while extracting response for type

    报错信息 feign.codec.DecodeException: Error while extracting response for type [java.util.List<cn.xxx ...

最新文章

  1. [20180412]订阅+镜像切换
  2. 使用Notepad++工具查看文件的十六进制
  3. hdu 1166 敌兵布阵 树状数组
  4. 某些小时后MySql连接自动掉线
  5. bzoj1046(HAOI2007)上升序列
  6. 机器学习之类别不平衡问题 (2) —— ROC和PR曲线
  7. Windows域控设置 AD域策略屏蔽端口 禁用端口【全域策略生效】
  8. 加入百度地图遇到 framework not found BaiduMapAPI***
  9. 10.XSD 元素替换
  10. maven没有servlet(创建servlet后报错)
  11. 未解决:火狐浏览器提示不安全的链接
  12. 青龙脚本--今日头条极速版
  13. 常用显示器,硬盘都有哪几种接口
  14. 手机上好用的APP推荐
  15. 图片批量下载 +图片马赛克:多张图片组成端午安康!
  16. 报表软件选型时应该知道的
  17. 四元数和欧拉角优缺点
  18. python语言实验指导答案_Python实验指导书
  19. HCIA ENSP WLAN基础配置
  20. pyecharts源码解读(12)图表类包charts之chart模块:常用图表基类Chart、直角坐标系图表基类RectChart、3D图表基类Chart3D

热门文章

  1. 微课|中学生可以这样学Python(例11.2):tkinter猜数游戏(1)
  2. Python对象特殊方法及其用法演示
  3. python write函数换行_python中文件的知识点总结
  4. react启动命令_十分钟搭建React开发环境
  5. .exe已停止工作_Windows 10累积更新KB4565503和KB4565483已发布
  6. zabbix无效监控项_使用zabbix模板监控tomcat-解决模板部分监控项不生效问题
  7. php百度语音合成,Drupal 与百度云语音合成(PHP SDK)的集成
  8. satoshi自动上色算法_再见,老照片!百年老照片修复算法,那些高颜值的父母!...
  9. kendoui固定宽度_KendoUi 学习笔记(二) Grid
  10. http和restful知识点查阅