Overview

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

I followed the instructions on the following site.

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

ImportError: cannot import name 'smart_text' from 'django.utils.encoding'

Upon investigation, I found the following article.

It suggested using djangorestframework-simplejwt instead.

Below are my notes on how to use it.

djangorestframework-simplejwt

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

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.