本文實(shí)例講述了Django框架用戶注銷功能實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
在圍場等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒ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è),圍場網(wǎng)站建設(shè)費(fèi)用合理。HttpResponse()
里有個delete_cookie()
方法專門用來刪除cookie
我們到此來完整的實(shí)現(xiàn)一下:訪問首頁如果沒有登錄,就跳轉(zhuǎn)到登錄頁面,登錄成功之后再跳轉(zhuǎn)回來的過程。
3個方法,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("") myReponse.set_cookie('userlogin_username',getUserName,3600) return myReponse else: msg['result'] = '用戶名或密碼錯誤' myReponse = render_to_response("login.html", msg) return myReponse # 用戶注銷 def logout(request): r = HttpResponse() r.delete_cookie('userlogin_username') r.write("") return r