How to make Token-Based Auth Rest API using Django rest framework

Django rest authentication application

Photo by Pakata Goh on Unsplash

Set-up of Django Rest Auth API

1. Create a virtual environment and name it “Auth”.
2. Activate the environment.
3. Install Django.
4. Install Django Rest Framework.
You will see something like this

I use Linux so the output is something like this.
5. Start the Django project: django-admin startproject AuthProject
6. Move to the directory “AuthProject”
7. write the command in terminal: python manage.py startapp mainApp

8. Install one more package by using this command: pip install django-rest-auth

Code of Django Authentication REST API

INSTALLED_APPS = ['django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles',#third part apps'rest_framework','rest_framework.authtoken','rest_auth',#Apps'mainApp',]
from django.contrib import adminfrom django.urls import path, includeurlpatterns = [path('admin/', admin.site.urls),path('rest-auth/', include('rest_auth.urls'))]

We are good to go for now. Open the terminal and migrate the apps.
python manage.py makemigrations
python manage.py migrate
python manage.py runserver
Something like this:

INSTALLED_APPS = ['django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles',#third part apps'rest_framework','rest_framework.authtoken','rest_auth','django.contrib.sites','allauth','allauth.account','rest_auth.registration',#Apps'mainApp',]SITE_ID = 1
urlpatterns = [path('admin/', admin.site.urls),path('rest-auth/', include('rest_auth.urls')),path('rest-auth/registration/',include('rest_auth.registration.urls'))]

--

--

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