flask的cookies操作
from flask import Flask,request,Response
app = Flask(__name__)
@app.route('/')
def hello_world():
res = Response('cookies的设置')
res.set_cookie('username','zhiliao')#cookies只有在响应返回的时候才能设置
return res
@app.route('/del/')
def delete_cookies():
res = Response('cookies的删除')
res.delete_cookie('username')#cookies只有在响应返回的时候才能删除
return res
if __name__ == '__main__':
app.run()
from flask import Flask,request,Response,Blueprint
from cms import bp
from datetime import datetime
from datetime import timedelta
app = Flask(__name__)
app.register_blueprint(bp) @app.route('/')
def hello_world():
res = Response('cookies的设置')
# expires = datetime(year=2018,month=11,day=5)
#expires是这么设置的
expires = datetime.now() + timedelta(days=13,hours=16)#这里一定要减8个小时
#在新版本的http协议中,expires参数视为被废弃的
#max_age,在IE8一下的浏览器是不支持的
# res.set_cookie('username','zhiliao',expires=expires)#cookies只有在响应返回的时候才能设置,
# max_age最大的cookies报存时间,expires到期时间
#使用expires参数,就必须使用格林尼治时间
#要相对北京时间少八个小时
res.set_cookie('username','zhiliao',domain='.hy.com')#在主域名前面加个点子域名就能用了
return res @app.route('/del/')
def delete_cookies():
res = Response('cookies的删除')
res.delete_cookie('username')#cookies只有在响应返回的时候才能删除
return res if __name__ == '__main__':
app.run()
from flask import Blueprint,request
bp = Blueprint('cms',__name__,subdomain='cms')
@bp.route('/')
def index():
username = request.cookies.get('username')
return 'cms 首页'

flask的cookies操作的更多相关文章
- C#语法糖之Cookies操作类 asp.net
用法: //声名一个数据集合 var listString = new List<string>() { "a", "b", "c&quo ...
- flask的orm操作
django是有orm操作的 可想而知 那么flask也是有orm操作的,其实flask的orm操作的使用和djnago的是差不多的 django的orm操作进行条件筛选的时候后面跟着的是objec ...
- Cookies操作类
实现代码: //声名一个数据集合 var listString = new List<string>() { "a", "b", "c&q ...
- C# 常用类库(字符串处理,汉字首字母拼音,注入攻击,缓存操作,Cookies操作,AES加密等)
十年河东,十年河西,莫欺少年穷 学无止境,精益求精 记录下字符串类库,方便今后查阅 主要包含了字符串解决,去除HTML,SQL注入攻击检测,IP地址处理,Cookies操作,根据身份证获取性别.姓名. ...
- AngularJs Cookies 操作
$cookiesProvider 使用$cookiesProvider改变$cookies服务的默认行为. 默认属性 path:字符串,cookies只在这个路径及其子路径可用.默认情况下,这个将会是 ...
- Angular Cookies 操作
$cookiesProvider 使用$cookiesProvider改变$cookies服务的默认行为. 默认属性 path:字符串,cookies只在这个路径及其子路径可用.默认情况下,这个将会是 ...
- Flask使用Flask-SQLAlchemy操作MySQL数据库
前言: Flask-SQLAlchemy是一个Flask扩展,简化了在Flask程序中使用SQLAlchemy的操作.SQLAlchemy是一个很强大的关系型数据库框架,支持多种数据库后台.SQLAl ...
- Flask 路由相关操作
URL Route URL 后接 / 作为目录级访问 URL 后不接 / 作为文件级访问 from flask import Flask app = Flask(__name__) @app.rout ...
- flask学习笔记(-操作数据库)
Python 数据库框架 大多数的数据库引擎都有对应的 Python 包,包括开源包和商业包.Flask 并不限制你使用何种类型的数据库包,因此可以根据自己的喜好选择使用 MySQL.Postgres ...
随机推荐
- Codeforces Round #453 (Div. 1) 901C C. Bipartite Segments
题 http://codeforces.com/contest/901/problem/C codeforces 901C 解 首先因为图中没有偶数长度的环,所以: 1.图中的环长度全是奇数,也就是说 ...
- Java小数中的四舍五入
1.怎么设置显示小数位数 public static void main(String[] args) { DecimalFormat decimalFormat = new DecimalForma ...
- learning gcc __BEGIN_DECLS and __END_DECLS
__BEGIN_DECLS and __END_DECLS be use for mix C and C++
- python_bisect模块的使用
这个模块只有几个函数, 一旦决定使用二分搜索时,立马要想到使用这个模块 import bisect L = [1,3,3,6,8,12,15] x = 3 x_insert_point = bisec ...
- 在windows下安装lxml 报错error: Unable to find vcvarsall.bat
刚开始安装 ,我是使用命令pip install lxml直接进行安装,不过出错了 error: Unable to find vcvarsall.bat 解决方案: 1.首先安装wheel,pip ...
- log4j.properties log4j.xml 路径问题
- Leetcode题目94.二叉树的中序遍历(中等)
题目描述: 给定一个二叉树,返回它的中序遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? 思路解析: 1 ...
- DDCTF-2019-writeup(7web+5misc)
一年前第一次参加了DDCTF,再次参加简单记录下web与misc的writeup Web Web1 滴~ 1.jpg参数可以包含文件,参数经过两次base64和一次16进制编码,将index.php编 ...
- C# 7 .NET / CLR / Visual Studio version requirements
C# 7 .NET / CLR / Visual Studio version requirements You do NOT need to target .NET 4.6 and above, ...
- leetcode39 组合总和
这道题想到的就是dfs,在累加的和大于或等于target时到达递归树的终点. 代码如下: class Solution { public: vector<vector<int>> ...