I have some users who are allowed to see a specific view.
So that users can log in and complain about 403 Forbidden for those users who cannot see this login, I can use the following (as described here ):
@permission_required('polls.can_vote', raise_exception=True) @login_required def my_view(request): ...
It really works as expected. But all of my views are class based. Starting with Django 1.9 (finally!), There are tons of good mixins for doing things that were only possible through decorators. But...
class MyClassView(LoginRequiredMixin, PermissionRequiredMixin, TemplateView): raise_exception = <???> permission_required = 'polls.can_vote' template_name = 'poll_vote.html'
this does not work. Since the raise_exception flag raise_exception used by both LoginRequiredMixin and PermissionRequiredMixin , I cannot set it.
- If
raise_exception is True , a user who is not registered gets 403 Forbidden (which I don't want). - If
raise_exception is False , a user who is not allowed to see the view will be redirected to the login page, which, since the user is logged in, will redirect to the page again. Creating a non-expert redirect cycle.
Of course, I could implement my own mixin, which behaves as I expected, but is there a way for Django to do this in the view itself? (not in urls.py )
source share