JWT Authentication Example
A snippet showing how to enable JWT authentication in DRF.
# Install SimpleJWT
pip install djangorestframework-simplejwt
# settings.py
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework_simplejwt.authentication.JWTAuthentication",
],
}
# urls.py
from django.urls import path
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
urlpatterns = [
path("api/jwt/token/", TokenObtainPairView.as_view(), name="jwt-obtain"),
path("api/jwt/refresh/", TokenRefreshView.as_view(), name="jwt-refresh"),
]
Explanation:
- Obtain access/refresh tokens via /api/jwt/token/; refresh to get a new access token.
- Category Django REST Framework (DRF)
- Total Views 832
- Last Modified 28 May, 2026
- Tags #drf #jwt #authentication #api
Previous snippet
Token Authentication Example
Next snippet