Overview

I wanted to use JWT with Django, so I tried djangorestframework-jwt.

https://github.com/jpadilla/django-rest-framework-jwt

I followed the instructions on the following site.

https://dev-yakuza.posstree.com/django/jwt/

However, when I added 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', the following error occurred.

ImportError:cannotimportname'smart_text'from'django.utils.encoding'

Upon investigation, I found the following article.

https://stackoverflow.com/questions/72102911/could-not-import-rest-framework-jwt-authentication-jsonwebtokenauthentication

It suggested using djangorestframework-simplejwt instead.

https://github.com/jazzband/djangorestframework-simplejwt

Below are my notes on how to use it.

djangorestframework-simplejwt

I was able to verify its operation by following the page below.

https://django-rest-framework-simplejwt.readthedocs.io/en/latest/getting_started.html

Postman

Send a POST request with username and password to the following endpoint.

http://localhost:8000/api/token/

As a result, you receive refresh and access tokens.

Using the access token value, set the Authorization header and send requests. By sending it in the format Bearer [jwt], I was able to use the API.

Summary

I hope this is helpful for using JWT with Django.