REST API (also known as RESTful API) is also supported via django-rest-framework (opens new window)

Developers can quickly expose API to the frontend apps or mobile apps.

# Consistent Signup, Login Behavior

The Signup, Login workflow are the same as the standard Django app. (django-allauth)

# How to use the API

  1. Please check tests code under django_app/tests/unittest/users/api
  2. Or check the API Doc, you can find entry URL of the API doc in django_app/urls.py

# Token

By default, we use JWT as our Token solution, which is a little different with the rest_framework.authtoken.

If you have no idea what JWT is, please check djangorestframework-simplejwt doc (opens new window) first.

Or you can switch back to rest_framework.authtoken in the Django settings file.

# Simple Example

# make sure the django dev server is running
$ python manage.py runserver
# run code below in the Django shell

import requests
from django.urls import reverse

# login
login_url = reverse("rest_login")
resp = requests.post(
    json={"username": "CHANGE-ME", "password": "CHANGE-ME"},

# if login succeed, use access_token in the next requests
data = resp.json()
access_token = data["access_token"]
user_pk = data["user"]["pk"]
detail_url = reverse("api-users:user-detail", args=(user_pk,))
resp = requests.put(
    data={"first_name": "michael"},
    headers={"Authorization": f"Bearer {access_token}"},

# Reference

  1. Blacklist app (opens new window)
  2. Revoke JWT Refresh Token (opens new window)