<div class="markdown-here-wrapper" data-md-url="https://i.cnblogs.com/EditPosts.aspx?postid=9962659">
<h1 id="cookie" style="margin: 20px 0px 10px; padding: 0px; font-weight: bold; color: black; font-size: 24px; border-bottom: 2px solid #aaaaaa;">cookie
<blockquote style="margin: 1.2em 0px; border-left: 4px solid #dddddd; padding: 0px 1em; color: #777777; quotes: none;">
<p style="margin: 0px 0px 1.2em !important; font-size: 16px; line-height: 1.75em; padding-right: 0.5em; padding-left: 0.5em;">Cookie 是在 HTTP 协议下,服务器或脚本可以维护客户工作站上信息的一种方式。Cookie 是由 Web 服务器保存在用户浏览器(客户端)上的小文本文件,它可以包含有关用户的信息。无论何时用户链接到服务器,Web 站点都可以访问 Cookie 信息
:
:
render(req,,{: })
<span class="hljs-function" style="color: #407ee7;"><span class="hljs-keyword" style="color: #6666ea;">def</span> <span class="hljs-title" style="color: #766e6b;">post</span><span class="hljs-params" style="color: #df5320;">(self,**kwargs)</span>:</span>
user = req.POST.get(<span class="hljs-string" style="color: #5ab738;">'user'</span>)
pwd = req.POST.get(<span class="hljs-string" style="color: #5ab738;">'pwd'</span>)
c = models.Administrator.objects.filter(username=user,password=pwd).count()
<span class="hljs-keyword" style="color: #6666ea;">if</span> c > <span class="hljs-number" style="color: #df5320;">0</span>:
rep = redirect(<span class="hljs-string" style="color: #5ab738;">'/index/'</span>)
newuser = user.encode(<span class="hljs-string" style="color: #5ab738;">'utf-8'</span>).decode(<span class="hljs-string" style="color: #5ab738;">'latin-1'</span>)
rep.set_cookie(<span class="hljs-string" style="color: #5ab738;">'username'</span>,newuser,max_age=<span class="hljs-number" style="color: #df5320;">10</span>)
<span class="hljs-keyword" style="color: #6666ea;">return</span> rep
<span class="hljs-keyword" style="color: #6666ea;">else</span>:
massage = <span class="hljs-string" style="color: #5ab738;">'用户名或密码错误'</span>
<span class="hljs-keyword" style="color: #6666ea;">return</span> render(req,{<span class="hljs-string" style="color: #5ab738;">'massage'</span>: massage})
<span class="hljs-function" style="color: #407ee7;"><span class="hljs-keyword" style="color: #6666ea;">def <span class="hljs-title" style="color: #766e6b;">index<span class="hljs-params" style="color: #df5320;">(req):
username=req.COOKIES.get(<span class="hljs-string" style="color: #5ab738;">'username')
<span class="hljs-keyword" style="color: #6666ea;">if username:
newuser=username.encode(<span class="hljs-string" style="color: #5ab738;">'latin-1').decode(<span class="hljs-string" style="color: #5ab738;">'utf-8')
<span class="hljs-keyword" style="color: #6666ea;">return render(req,<span class="hljs-string" style="color: #5ab738;">"app1/index.html",{<span class="hljs-string" style="color: #5ab738;">"name": newuser})
<span class="hljs-keyword" style="color: #6666ea;">return redirect(<span class="hljs-string" style="color: #5ab738;">"/login")
<p style="margin: 0px 0px 1.2em !important; font-size: 16px; line-height: 1.75em; padding-right: 0.5em; padding-left: 0.5em;">查看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

(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|