Search code examples
djangodjango-rest-frameworkdjango-authentication

Named url kwargs in authenticate method


I'm trying to create a custom authentication class in the Django rest framework. In the authenticate(self, request) method, at first glance, it seems that there is no way to get named kwarg from the URL. Is there a way to accomplish this?


Solution

  • You can get url via request.get_full_path():

    def authenticate(self, request):
        ...
        url = request.get_full_path()
    

    Check django docs in https://docs.djangoproject.com/en/3.2/topics/auth/customizing/#writing-an-authentication-backend you might find it useful