Last active
December 21, 2021 14:28
-
-
Save Sheikh2Imran/89dbafc0f464b494477930f60b7e7356 to your computer and use it in GitHub Desktop.
Custom method decorator in Django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def authentication_decorator(function): | |
def wrap(request, *args, **kwargs): | |
user_token = request.META.get('HTTP_AUTHORIZATION') | |
user_response, status_code = backend_obj.get_user(user_token) | |
if status_code == 200: | |
kwargs = user_response | |
return function(request, *args, **kwargs) | |
return wrap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views import View | |
from django.http import HttpResponse | |
from django.utils.decorators import authentication_decorator | |
from .decorators import authentication_decorator | |
class IntroductionView(View): | |
message = "Have a good day sir" | |
@method_decorator(authentication_decorator) | |
def get(self, request): | |
return HttpResponse(self.greeting) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment