79711266

Date: 2025-07-23 03:18:28
Score: 1
Natty:
Report link

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

Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @dirkgroten
  • Low reputation (0.5):
Posted by: Gabriel Tkacz