1. 程式人生 > >login_required裝飾器(1)

login_required裝飾器(1)

login_required裝飾器:

如果沒有登入:

當請求http://192.168.137.3:9000/lockIndex/

會跳轉到http://192.168.137.3:9000/accounts/login/?next=/lockIndex/

def lockIndex(req):
         print 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
         print '-----------------request.user.is_authenticated()';
         print req.user.is_authenticated()
         if not req.user.is_authenticated():
              return redirect('/index')
         print '-----------------request.user.is_authenticated()';

         print '---------lockIndex--------------'
         from django.conf import settings
         print req.user
         print settings.LOGIN_URL
         print '---------lockIndex--------------'
         return render_to_response('lockIndex.html')

		 
[19/Sep/2018 10:15:06] "GET /lockIndex/ HTTP/1.1" 302 0
[19/Sep/2018 10:15:06] "GET /accounts/login/?next=/lockIndex/ HTTP/1.1" 200 1189
[19/Sep/2018 10:15:06] "GET /static/news/Css/Index/index.css HTTP/1.1" 304 0
[19/Sep/2018 10:15:06] "GET /static/news/scan.jpg HTTP/1.1" 304 0
[19/Sep/2018 10:15:06] "GET /static/news/login.jpg HTTP/1.1" 304 0
Not Found: /favicon.ico
[19/Sep/2018 10:15:06] "GET /favicon.ico HTTP/1.1" 404 7565

根本不會呼叫這個lockIndex方法。