django-hijack失败,从Django 2.1.0开始,出现UserPassesTestMixin

时间:2019-06-25 17:14:36

标签: python django

显然,从Django 2.1.0开始,django-hijack(版本2.1.10)与UserPassesTestMixin一起使用时似乎会出错。测试通过时工作正常;如果测试失败,则会收到403禁止错误,而不是重定向到login_url。

这是一个错误吗?如果是这样,我该如何修补该软件包以使其与Django 2.1.0+兼容?

class MyView(UserPassesTestMixin, View):
    test_func = lambda self: False
    login_url = '/myurl/'

    def get(self, request):
        return HttpResponse('Hello world')
[25/Jun/2019 13:03:29] "GET /hijack/username/someuser/ HTTP/1.1" 302 0
Forbidden (Permission denied): /myview/
Traceback (most recent call last):
  File "C:\Envs\myenv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Envs\myenv\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Envs\myenv\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "c:\program files\python36\Lib\contextlib.py", line 52, in inner
    return func(*args, **kwds)
  File "C:\Envs\myenv\lib\site-packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "C:\Envs\myenv\lib\site-packages\django\views\generic\base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Envs\myenv\lib\site-packages\django\contrib\auth\mixins.py", line 52, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "C:\Envs\myenv\lib\site-packages\django\contrib\auth\mixins.py", line 108, in dispatch
    return self.handle_no_permission()
  File "C:\Envs\myenv\lib\site-packages\django\contrib\auth\mixins.py", line 43, in handle_no_permission
    raise PermissionDenied(self.get_permission_denied_message())
django.core.exceptions.PermissionDenied
[25/Jun/2019 13:03:29] "GET /myview/ HTTP/1.1" 403 22

0 个答案:

没有答案