本文共 2266 字,大约阅读时间需要 7 分钟。
直接导包,用点访问就有
@blue.route('/requrest')def get_request(): return request.host
args: 得到的请求参数字典;(元组形成的列表)
form:得到post,put,patch方法里面的参数:格式和上面差不多;
files :文件上传:原生实现,插件实现
heads:请求头:
获取immutableMultiDict中的值:
----前面知识总结---------
flask :
基于python的Web的微框架:
内置两大核心模块:
使用到的拓展包:
App包里面 init.py 文件是模块里最先加载的,并且是单例的;
view: 路由器传参数
return 'xxx',200
#return 'sleeping ',400 response = make_response('hhh') # 通过观看源码,自己造一个respose对象: response = Response('自己dit一个resposse')
# @app下面是全局处理,blue下面就单个蓝图处理@blue.errorhandler(404)def hander404(e): return '404 找不到啦,傻子哦'
创建response三种方式:
参数设置:
reder_template:
HttpEXception:
几大实现技术
Cookie: 客户端会话技术,
数据存在客户端。
key-value格式进行存储
html文件form中使用进行反向路由:
<form action= "{ { url_for('blue.login') }}" method="post"> </form>
过程就是 在post的时候 将值存在cookie里面,然后验证或者需要的时候取出来:
@blue.route('/login',methods=['POST','GET'])def login(): if request.method == 'GET': return render_template('login.html') if request.method == 'POST': username = request.form.get('username') response = make_response('登陆成功 %s' %username) # 添加cookie: response.set_cookie('username',username) return response@blue.route('/mine')def mine(): username = request.cookies.get('username') return 'welcome %s ' %username
cookie默认支持中文
Session
将session存到redis中去。
将数据进行了pickle序列化
Token :没说。。。
转载地址:http://acywi.baihongyu.com/