actualización de metodo depreciado

parent b28ed46e
from django.shortcuts import HttpResponseRedirect from django.shortcuts import HttpResponseRedirect
from django.urls import reverse from django.urls import reverse
# from django.core.urlresolvers import reverse # from django.core.urlresolvers import reverse
class AuthRequiredMiddleware(object): class AuthRequiredMiddleware(object):
def __init__(self, get_response): def __init__(self, get_response):
self.get_response = get_response self.get_response = get_response
def __call__(self, request): def __call__(self, request):
# Code to be executed for each request before # Code to be executed for each request before
# the view (and later middleware) are called. # the view (and later middleware) are called.
response = self.get_response(request) response = self.get_response(request)
print (request.path_info) print(request.path_info)
print (reverse('login')) print(reverse('login'))
# if request.path_info == reverse('ws-news-list2'): # if request.path_info == reverse('ws-news-list2'):
# return response # return response
if not request.user.is_authenticated() and request.path_info != reverse('login'): if not request.user.is_authenticated and request.path_info != reverse('login'):
return HttpResponseRedirect(reverse('login')) return HttpResponseRedirect(reverse('login'))
# Code to be executed for each request/response after # Code to be executed for each request/response after
# the view is called. # the view is called.
return response return response
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment