4👍
✅
the UserPassesTestMixin
mixin can be used to this effect. Basically, write a View Class that implements the test_func
function. This function has access to self
so you can read the URL and the user. if the test_func returns True
, the user is allowed to go on, otherwise is passed to access control (probably redirected to the login form if configured).
Source:stackexchange.com