An update on @dirkgroten answer: now you need to access the key defined in the USER_ID_CLAIM Simple JWT setting, which defaults to user_id
. Which means that, to get the pk of the calling user from a request, you would do something like:
@api_view(['POST'])
def some_api_call(request, *args, **kwargs):
user_pk = request.user_id
This variable name is entirely configurable with the JWT settings. See more at: https://django-rest-framework-simplejwt.readthedocs.io/en/latest/settings.html#user-id-claim