I'm currently using Django Rest Framework JWT for authentication on a project. I have already implemented BasicAuthentication, SessionAuthentication and JSONWebTokenAuthentication where users can request a token by using the POST method for every new session. However, I would like the token to be created (and possibly viewable in the admin section) immediately after each user is created.
I took a look at the Django Rest Framework JWT documentation where it states that tokens can be manually created using:
from rest_framework_jwt.settings import api_settings
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)
I tried putting this code snippet in views.py, models.py and serializers.py but I keep getting a reference error on the "user".
Any help on how to correctly implement this code snippet or an alternative method will be greatly appreciated. Thanks