本文實(shí)例講述了Django框架用戶注銷功能實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
在圍場(chǎng)等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計(jì)、網(wǎng)站制作 網(wǎng)站設(shè)計(jì)制作定制網(wǎng)站,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),全網(wǎng)營銷推廣,外貿(mào)營銷網(wǎng)站建設(shè),圍場(chǎng)網(wǎng)站建設(shè)費(fèi)用合理。HttpResponse()
里有個(gè)delete_cookie()
方法專門用來刪除cookie
我們到此來完整的實(shí)現(xiàn)一下:訪問首頁如果沒有登錄,就跳轉(zhuǎn)到登錄頁面,登錄成功之后再跳轉(zhuǎn)回來的過程。
3個(gè)方法,index、login、logout
# coding:utf-8 from django.shortcuts import render,render_to_response # Create your views here. from django.http import HttpResponse from UserClass import UserLogin def index(request): msg = {'username':'guest'} if request.COOKIES.get('userlogin_username') != None : msg['username'] = request.COOKIES.get('userlogin_username') myReponse = render_to_response("index.html",msg) return myReponse def login(request): msg = {'result': ''} if request.method == 'POST': getUserName = request.POST.get('username') getPwd = request.POST.get('pwd') # 實(shí)例化UserLogin類 loginObj = UserLogin(getUserName,getPwd) if loginObj.isLogin(): myReponse = HttpResponse("<script>self.location='/index'</script>") myReponse.set_cookie('userlogin_username',getUserName,3600) return myReponse else: msg['result'] = '用戶名或密碼錯(cuò)誤' myReponse = render_to_response("login.html", msg) return myReponse # 用戶注銷 def logout(request): r = HttpResponse() r.delete_cookie('userlogin_username') r.write("<script>self.location='/index'</script>") return r
網(wǎng)頁標(biāo)題:Django框架用戶注銷功能實(shí)現(xiàn)方法分析-創(chuàng)新互聯(lián)
文章地址:http://aaarwkj.com/article2/jcsoc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、品牌網(wǎng)站建設(shè)、網(wǎng)站制作、App開發(fā)、網(wǎng)站設(shè)計(jì)公司、動(dòng)態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容