Django Rest Framework Token Authentication

Adi Ramadhan
2 min readJul 17, 2020

Create DRF REST API with Token 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, rest_framework and rest_framework.authtoken in INSTALLED_APPS


Add REST_FRAMEWORK in myproject/

'rest_framework.authentication.TokenAuthentication', # new

Step 5: Migrate
Migrate rest framework model: python migrate

Step 6: Testing
Generate token for user admin for testing purpose:
python drf_create_token admin

Generated token for user admin

Run server: python runserver

Test call API using POSTMAN. Download and see official docs here.
Authorization: Token <token>