<div data-md-url="https://i.cnblogs.com/Editposts.aspx?postID=9962659">
<h1 ID="cookie" >cookie
<blockquote >
<p >cookie 是在 http 协议下,服务器或脚本可以维护客户工作站上信息的一种方式。cookie 是由 Web 服务器保存在用户浏览器(客户端)上的小文本文件,它可以包含有关用户的信息。无论何时用户链接到服务器,Web 站点都可以访问 cookie 信息
: : render(req,,{: })<span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-function" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #407ee7;"><span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-keyword" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #6666ea;">def</span> <span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-<a href="https://m.jb51.cc/tag/Title/" target="_blank" >Title</a>" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #766e6b;">post</span><span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-p<a href="https://www.jb51.cc/tag/ara/" target="_blank" >ara</a>ms" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #df5320;">(self,**<a href="https://www.jb51.cc/tag/kwargs/" target="_blank" >kwargs</a>)</span>:</span> user = req.POST.get(<span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-string" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #5ab738;">'user'</span>) pwd = req.POST.get(<span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-string" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #5ab738;">'pwd'</span>) c = models.<a href="https://m.jb51.cc/tag/admin/" target="_blank" >admin</a>istrator.objects.filter(user<a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a>=user,password=pwd).count() <span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-keyword" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #6666ea;">if</span> c > <span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-number" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #df5320;">0</span>: rep = redirect(<span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-string" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #5ab738;">'/index/'</span>) newuser = user.encode(<span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-string" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #5ab738;">'utf-8'</span>).decode(<span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-string" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #5ab738;">'latin-1'</span>) rep.set_<a href="https://m.jb51.cc/tag/cookie/" target="_blank" >cookie</a>(<span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-string" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #5ab738;">'user<a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a>'</span>,newuser,max_age=<span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-number" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #df5320;">10</span>) <span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-keyword" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #6666ea;">return</span> rep <span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-keyword" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #6666ea;">else</span>: massage = <span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-string" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #5ab738;">'<a href="https://www.jb51.cc/tag/yonghuming/" target="_blank" >用户名</a>或密码<a href="https://www.jb51.cc/tag/cuowu/" target="_blank" >错误</a>'</span> <span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-keyword" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #6666ea;">return</span> render(req,{<span https://m.jb51.cc/tag/Js/" target="_blank" >Js</a>-string" https://m.jb51.cc/tag/color/" target="_blank" >color</a>: #5ab738;">'massage'</span>: massage})
<span ><span >def
<span >index<span >(req):
username=req.cookieS.get(<span >'username')
<span >if username:
newuser=username.encode(<span >'latin-1').decode(<span >'utf-8')
<span >return render(req,<span >"app1/index.HTML",{<span >"name": newuser})
<span >return redirect(<span >"/login")
<p >查看set_cookie参数
,max_age=None,expires=None,path=,domain=None,secure=False,httponly=False,samesite=None):
)
c > : req.session[] = req.session[] = user redirect() : massage = render(req,{: massage})
: : is_login = request.session.get() is_login: func(request,**kwargs) : redirect() inner
SESSION_cookie_PATH = SESSION_cookie_DOMAIN = SESSION_cookie_SECURE = SESSION_cookie_httpONLY = SESSION_cookie_AGE = SESSION_EXPIRE_AT_broWSER_CLOSE = SESSION_SAVE_EVERY_REQUEST =
总结 以上是内存溢出为你收集整理的Django之cookie&session全部内容,希望文章能够帮你解决Django之cookie&session所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)