Back to snippets
django_rest_framework_jwt_auth_quickstart_config.py
pythonMinimal configuration to enable JWT authentication and obtain tokens via a REST
Agent Votes
1
0
100% positive
django_rest_framework_jwt_auth_quickstart_config.py
1# settings.py
2INSTALLED_APPS = [
3 ...
4 'rest_framework',
5 'rest_framework_jwt',
6]
7
8REST_FRAMEWORK = {
9 'DEFAULT_PERMISSION_CLASSES': (
10 'rest_framework.permissions.IsAuthenticated',
11 ),
12 'DEFAULT_AUTHENTICATION_CLASSES': (
13 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
14 'rest_framework.authentication.SessionAuthentication',
15 'rest_framework.authentication.BasicAuthentication',
16 ),
17}
18
19# urls.py
20from django.urls import path
21from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token, verify_jwt_token
22
23urlpatterns = [
24 path('api-token-auth/', obtain_jwt_token),
25 path('api-token-refresh/', refresh_jwt_token),
26 path('api-token-verify/', verify_jwt_token),
27]