定义登录页面
编辑views.py:
loginurl_default = '../login' def login_req(url=loginurl_default): def getFun1(func): def wrapper(request,*args, **kv): global user_loggedin userinfo=request.session.get('uu',None) if not userinfo: #user_loggedin='GUEST' print 'url is: ',url return HttpResponseRedirect(url) #没有登录,则跳转到登录页面 else: print 'deco already logined uu is: ',request.session['uu'],request.session.get('uu',None) user_loggedin=request.session['uu'] #print dir(request.session['uu']) print 'deco user_loggedin is : ' ,user_loggedin return func(request,*args, **kv) return wrapper return getFun1
@login_req() #默认使用../login页面,也可以自定义为其他页面,如@login_req('../abc') def testvw(request):