-1👍
Once you create your own handler method you’ll have to change it in the JWT_AUTH setting. Check out the Additional Settings section in the docs.
28👍
I found success doing the following:
myapp.view.py file:
def jwt_response_payload_handler(token, user=None, request=None):
return {
'token': token,
'bunny': 'fu fu'
}
setting.py file:
JWT_AUTH = {
'JWT_RESPONSE_PAYLOAD_HANDLER':
#'rest_framework_jwt.utils.jwt_response_payload_handler',
'myapp.views.jwt_response_payload_handler',
}
Implementing the function jwt_response_payload_handler
in an arbitrary location, but make sure it is in your python path. For example in this file: myapp.views.py
Then in your settings.py file update the JWT_AUTH
dictionary key JWT_RESPONSE_PAYLOAD_HANDLER
with the new location of the jwt_response_payload_handler
you just created.
Once you grasp what’s going on, you can adapt the solution how you would like. For example, I would not recommend leaving your overridden function in the views.py file. It was just simpler for demonstrating purposes.
Perhaps placing the jwt_response_payload_handler
function in a “helper.py” file you create would be a simple solution.
- Django Gunicorn not load static files
- Registered models do not show up in admin
- Inform user that email is invalid using Django's Password Reset
- What am I not doing right in this django file upload form?
0👍
jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
payload = jwt_payload_handler(user)
token = jwt_encode_handler(payload)
- Csrf_token of Django into Vuejs when seperate them
- What is the use of __table_args__ = {'extend_existing': True} in SQLAlchemy?