Hey there! This problem might be a bit unpredictable, but give it a go and let us know how you do!
Create a mixin class called AdminOnlyMixin that checks if a user is authenticated and a staff member before allowing access to a view. If the user doesn't have permission, show an "Access denied" message. Fill the blanks in the code to make it work.Built-in and custom mixins for Class Based Views
Gatekeeper's delight in the digital realm
Report a typo
Fill in the gaps with the relevant elements
class AdminOnlyMixin:
def (self, request, *args, **kwargs):
if not request.user.is_authenticated or not request.user.is_staff:
return self.handle_no_permission()
return ().dispatch(request, *args, **kwargs)
def handle_no_permission(self):
return ("Access denied. Admin only.")Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.