Home > Back-end >  Trouble in getting params pk or id in Django rest framework has_permission
Trouble in getting params pk or id in Django rest framework has_permission

Time:11-14

I have trouble in getting the params pk in my url, resources/<int:pk> in the my django rest framework permission.

def has_permission(self, request, view):
    #extract params pk here
    pass

I tried request.POST.get('pk') but it returns nothing.

CodePudding user response:

You can access the URL parameters via view.kwargs

def has_permission(self, request, view):
    pk = view.kwargs.get('pk')
    ...

CodePudding user response:

Oh I think I got it. I use view.kwargs.get('pk')

I got my answer from a similar question in here. How can I access URL parameters from within a BasePermission?

  • Related