How can I access URL parameters from within a BasePermission?

If you can't pass them in directly (which would be preferable), they are available on the request object:

company_id = request.resolver_match.kwargs.get('company_id')

request.resolver_match.args and request.resolver_match.kwargs contain the positional/keyword arguments captured in your url.


As an alternative to the correct response posted by knbk, you can also get the URL parameters using the view object passed to has_permission method. Like this:

company_id = view.kwargs.get('company_id')