Django Rest Framework Basic Authentication

Adi Ramadhan
2 min readJul 18, 2020

Create DRF REST API with Basic Authentication.
Official docs here.

Step 1: Preparation, Create Django Project, Initial Migration
Install virtualenv: pip install virtualenv
Create virtualenv: virtualenv venv
Start virtualenv: venv/Scripts/activate
Install Django, DRF in virtualenv: pip install django djangorestframework
Create Django: django-admin startproject myproject
Go to myproject folder: cd myproject
Initial Migration: python migrate
Create superuser: python createsuperuser
(for example: username=admin)

Step 2: Create App
Create app: python createapp myapp
Create API in myapp/


Step 3: Set up urls
Create myapp/


Update myproject/


Step 4:
Register myapp and rest_framework in INSTALLED_APPS

INSTALLED_APPS in myproject/

Step 6: Testing
Run server: python runserver
Test call API using POSTMAN. Download and see official docs here. with Basic Auth with user that created before (see Step 1),