Django Rest Framework Basic Authentication

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),



Software Engineer, Indonesia

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