get_test_func()
You can also override the get_test_func()
method to have the mixin use a differently named function for its checks (instead of test_func()
).
Stacking UserPassesTestMixin
Due to the way UserPassesTestMixin
is implemented, you cannot stack them in your inheritance list. The following does NOT work:
class TestMixin1(UserPassesTestMixin): def test_func(self): return self.request.user.email.endswith('@example.com') class TestMixin2(UserPassesTestMixin): def test_func(self): return self.request.user.username.startswith('django') class MyView(TestMixin1, TestMixin2, View): ...
If TestMixin1
would call super()
and take that result into account, TestMixin1
wouldn’t work standalone anymore.
Please login to continue.