def login_auth(func):
def inner(request, * args, * * kwargs):
is_login = request.COOKIES.get( 'is_login' )
print (is_login)
if is_login = = 'True' :
res = func(request, * args, * * kwargs)
print ( '##############################' )
return res
else :
return redirect( 'login' )
return inner
@login_auth
def index(request):
return render(request, 'cookies/index.html' )
@login_auth
def home(request):
return render(request, 'cookies/home.html' )
def login(request):
if request.method = = 'GET' :
return render(request, 'cookies/login.html' )
else :
username = request.POST.get( 'username' )
password = request.POST.get( 'password' )
if username = = 'bge' and password = = '666' :
path = request.GET.get( 'returnurl' )
if path:
ret = redirect(path})
else
ret = redirect( 'index' )
ret.set_cookie( 'is_login' , True )
return ret
else :
return HttpResponse( '登录失败' )
|