Cookie:
Cookie直接的表现就是知道用户是否登录
发起请求的时候,浏览器就自动带上该域名下cookie
Cookie是在存在浏览器当中
Cookie默认过期时间是关闭浏览器就过期
通过 max_age 设置多少秒过期
通过expries 设置具体多长时间过期
max_age与expries只能二选一
可以通过delete_cookie删除

JsonResponse
xml 是一种数据格式
json 是一种数据格式 是一种特殊的字符串
只返回数据的接口(API)
API==接口
把字典转成json的话 就是json.dumps()
把json转成字典的话 就是json.loads()
HttpResponse 默认content_type text/html
JsonResponse 默认content_type application/json
JSON校验格式化工具网址:http://www.bejson.com/

重定向
永久重定向 301
临时重定向 302
应用级路由 别名--->name
根级路由 别名--->namespace
reverse() 通过路由的别名重定向是相对正确的做法
带有关键字重定向---kwargs={}
带有位置参数重定向---args=()



Session
cookies是存在浏览器当中 ,相对不安全
session是存在服务器当中 , 相对安全
django 通过中间件默认启用了session
session依赖cookie的 cookie存的是session_id
表结构包括三个数据:键,值,过期时间。
值是base64加密
clear 是清除值部分
flush 清除整个session
del request.session['键'] # 删除某个值
session默认的过期是两周


网友评论