.):
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
Authorization: Bearer <token>pip install djangorestframework_simplejwtREST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
],
}
urls.pyfrom django.urls import path
from rest_framework_simplejwt import views as jwt_views
urlpatterns = [
# Your URLs...
path('api/token/', jwt_views.TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/token/refresh/', jwt_views.TokenRefreshView.as_view(), name='token_refresh'),
]
views.py, import Response and IsAuthenticatedfrom rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
class HelloView(APIView):
permission_classes = (IsAuthenticated,)
def get(self, request):
content = {'message': 'Hello, World!'}
return Response(content)
urls.py to reflect the route you want for the viewfrom django.urls import path
from myapi.core import views
urlpatterns = [
path('hello/', views.HelloView.as_view(), name='hello'),
]
/api/token/
POST requesthttp post http://127.0.0.1:8000/api/token/ username=harper password=123access and refresh tokens and store in localStoragehttp http://127.0.0.1:8000/hello/ "Authorization: Bearer <access_token>"/api/token/refresh/ endpoint and post the refresh token
http post http://127.0.0.1:8000/api/token/refresh/ refresh=<refresh_token>python manage.py runserver is for development onlyuwsgi.py file, which contains a function to be called by the application server. This function gets a Python object representing the incoming request.python manage.py makemigrations
python mangage.py migrate
python mangage.py makemigrations <app_name> && python manage.py migrate <app_name>
python manage.py makemigrations <app_name> --name <migration_name>python manage.py migrate <app_name> <migration_to_revert_to>