191107Django的Cookie和Session
- Cookie的使用
from django.shortcuts import render,redirect
def login(request):
print("1",request.COOKIES)
if request.method == "POST":
name = request.POST.get("user")
pwd = request.POST.get("pwd")
if name == "dongfei" and pwd == "dongfei":
ret = redirect("/index")
ret.set_cookie("id",'14bae99719abcf1f89f5',max_age=10) #设置cookie的超时时间
return ret
return render(request,"login.html",locals())
def index(request):
if request.COOKIES.get("id",None) == '14bae99719abcf1f89f5':
name = "dongfei"
return render(request,"index.html",locals())
else:
return redirect("/login/")
- Cookie和Session的使用
from django.shortcuts import render,redirect
def login(request):
print("COOKIES",request.COOKIES)
print("SESSION",request.session)
if request.method == "POST":
name = request.POST.get("user")
pwd = request.POST.get("pwd")
if name == "dongfei" and pwd == "dongfei":
# ret = redirect("/index")
# ret.set_cookie("id",'14bae99719abcf1f89f5',max_age=10) #设置cookie的超时时间
# return ret
request.session["is_login"] = True #设置session,需要migrate数据库
request.session["user"] = name
# del request.session["user"] #删除session
# request.session.set_expiry(10) #设置session超时时间
return redirect("/index/")
return render(request,"login.html",locals())
def index(request):
# if request.COOKIES.get("id",None) == '14bae99719abcf1f89f5':
# name = "dongfei"
# return render(request,"index.html",locals())
if request.session.get("is_login",None):
name = request.session.get("user")
return render(request,"index.html",locals())
else:
return redirect("/login/")
191107Django的Cookie和Session的更多相关文章
- Cookie和Session的总结
1.开篇 在之前学习这一段的时候我一直有点没弄清楚,其实对Session这块的理解还可以,但是Cookie感觉始终还是欠缺点火候.之后的很长一段时间都基本上很少用Cookie了,渐渐的也淡忘了这一块的 ...
- java的会话管理:Cookie和Session
java的会话管理:Cookie和Session 1.什么是会话 此处的是指客户端(浏览器)和服务端之间的数据传输.例如用户登录,购物车等 会话管理就是管理浏览器客户端和服务端之间会话过程产生的会话数 ...
- Cookie和Session的那些事儿
Cookie和Session都是为了保持用户的访问状态,一方面为了方便业务实现,另一方面为了简化服务端的程序设计,提高访问性能.Cookie是客户端(也就是浏览器端)的技术,设置了Cookie之后,每 ...
- django的cookie和session以及内置信号、缓存
cookie和session cookie和session的作用: cookie和session都记录了客户端的某种状态,用来跟踪用户访问网站的整个回话.两者最大的区别是cookie的信息是存放在浏览 ...
- Cookie和Session的区别
前言 HTTP是一种无状态的协议,为了分辨链接是谁发起的,就需要我们自己去解决这个问题.不然有些情况下即使是同一个网站我们每打开一个页面也都要登录一下.而Session和Cookie就是为解决这个问题 ...
- 本地数据Store。Cookie,Session,Cache的理解。Timer类主要用于定时性、周期性任务 的触发。刷新Store,Panel
本地数据Store var monthStore = Ext.create('Ext.data.Store', { storeId : 'monthStore', autoLoad : false, ...
- Cookie与Session
再说Cookie与Session之前,先要了解一下http协议. 何为http协议: http协议即超文本传输协议,一种基于浏览器请求与服务器响应的协议,该协议主要的特点就是它是一种无状态的协议(只针 ...
- 【转】Cookie和Session区别和联系详解
会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录信息确定用户身份,Session通过在服务器端 ...
- 理解Cookie和Session机制(转)
目录[-] Cookie机制 什么是Cookie 记录用户访问次数 Cookie的不可跨域名性 Unicode编码:保存中文 BASE64编码:保存二进制图片 设置Cookie的所有属性 Cookie ...
随机推荐
- ado.net SqlHelp类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 简单 UDP 操作类
using System; using System.Collections.Generic; using System.Text; using System.Net; using System.Ne ...
- 数据绑定-Java的基本数据类型绑定
Demo.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...
- 分布式的几件小事(二)dubbo的工作原理
1.dubbo的工作原理 ①整体设计 图例说明: 图中左边淡蓝背景的为服务消费方使用的接口,右边淡绿色背景的为服务提供方使用的接口,位于中轴线上的为双方都用到的接口. 图中从下至上分为十层,各层均为单 ...
- java 关于数字取小数点后两位出现整数0没有的问题
最近再项目中对取到的一系列带很长小数的数字,展现时要求去小数点后两位显示就可以了 开始我是以下写法: double a = 0.1234455; DecimalFormat decimalForm ...
- 精通shell编程--最后的总结
不得不说shell语法是丑陋的,操作是简单高效的,最后一次学习总结shell shell总结 字符串删除与替换等常见操作 ## 字符串长度 a=1234 echo "${#a}" ...
- linux命令详解——sort
[原文链接]:http://www.cnblogs.com/51linux/archive/2012/05/23/2515299.html 1 sort的工作原理 sort将文件的每一行作为一个单位, ...
- 3.1.2-arm-linux-ld选项
有文件link.S,内容如下 .text .global _start _start: b step1 step1: ldr pc, =step2 step2: b step2 经过如下命令编译 ar ...
- VMware虚拟化集群的配置(一)
一.VMware介绍 VMware vSphere 是业界领先且最可靠的虚拟化平台.vSphere将应用程序和操作系统从底层硬件分离出来,从而简化了 IT操作. VMware集群最主要的两个部分ESX ...
- deep_learning_Function_tf.add()、tf.subtract()、tf.multiply()、tf.div()
tf.add().tf.subtract().tf.multiply().tf.div()函数介绍和示例 1. tf.add() 释义:加法操作 示例: x = tf.constant(2, dtyp ...