UserPassesTestMixin
Deny a request with a permission error if the test_func() method returns False.
Methods
test_func()
@classmethod
def test_func() - > boolean
Raises a NotImplementedError to ensure subclasses provide their own logic for determining if a user has permission to access the view.
Returns
| Type | Description |
|---|---|
boolean | A boolean value indicating whether the user passes the defined permission test. |
get_test_func()
@classmethod
def get_test_func() - > callable
Override this method to use a different test_func method.
Returns
| Type | Description |
|---|---|
callable | The function or method that will be executed to perform the permission check. |
dispatch()
@classmethod
def dispatch(
request: [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest),
*args: tuple,
**kwargs: dict
) - > [HttpResponse](../../../http/response/httpresponse.md?sid=django_http_response_httpresponse)
Executes the permission test before processing the request; if the test fails, it triggers the handle_no_permission logic.
Parameters
| Name | Type | Description |
|---|---|---|
| request | [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest) | The current HTTP request object being processed. |
| *args | tuple | Positional arguments passed to the view. |
| **kwargs | dict | Keyword arguments passed to the view. |
Returns
| Type | Description |
|---|---|
[HttpResponse](../../../http/response/httpresponse.md?sid=django_http_response_httpresponse) | The standard HTTP response from the parent dispatch method or the result of handle_no_permission if the test fails. |