Django rest framework Part 2: Custom Authentication

Authentication

JWT Tokens

Installing PyJWT

Updating the Models

from datetime import datetime, timedelta
from django.conf import settings
import jwt

Authentication module

Login Endpoint(Views)

from .serializers import LoginSerializer

Handling Urls

from .views import LoginAPIViewurlpatterns = [
...
path(‘login/’, LoginAPIView.as_view(), name=’user-registration’)
]

Finally! Lets run

$ python manage.py runserverSystem check identified no issues (0 silenced).
March 01, 2021–18:21:03
Django version 3.1.7, using settings ‘app.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store