后来,好多人代替了好多人☁️|

little小新

园龄:2年6个月粉丝:8关注:0

7、flask-response响应

# 路由 + 视图函数
from flask import Blueprint, request, render_template, jsonify, Response
# from models import *
#蓝图
# 创建蓝图对象
# 第一个参数:蓝图的名字
# 第二个参数:蓝图的包名
blue = Blueprint('user', __name__,)
@blue.route('/') # 路由
def index():
return 'user index'
# 请求和响应
#response响应
@blue.route('/response/')
def get_response():
pass
#响应的几种方式
# 1. 返回字符串
# return 'response'
# 2.模板渲染(前后端不分离)
# return render_template('index.html', name='zhangsan', age=18)
# # 3.返回json数据(前后端分离)
# data = {'name': 'zhangsan', 'age': 18}
# # return data
# return jsonify(data) # 序列化、将字典转为字符串
#
# 4. 自定义响应对象
html = render_template('index.html', name='zhangsan', age=18)
print(html, type(html))
# res = make_response(html, 200)
res = Response(html, 200)
return res

 

本文作者:little小新

本文链接:https://www.cnblogs.com/littlecc/p/18288526

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   little小新  阅读(27)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起