在 authenticate 方法中命名为 url kwargs

Named url kwargs in authenticate method

我正在尝试在 Django 休息框架中创建自定义身份验证 class。在 authenticate(self, request) 方法中,乍一看,似乎没有办法从 URL 中获取 named kwarg。有办法实现吗?

您可以通过 request.get_full_path():

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

查看 https://docs.djangoproject.com/en/3.2/topics/auth/customizing/#writing-an-authentication-backend 中的 django 文档,您可能会发现它有用