Last updated November 18, 2025

Originally published on October 26, 2025

Quickly test Django endpoints locally

Ever wanted to test your Django endpoints before the front end is ready? You sure can.

Turns out Django’s testing tools aren’t just for TestCase classes:

from django.test import Client

client = Client()

This little object is where all the magic begins - a simple yet powerful gateway for simulating requests.

Need to hit endpoints that require authentication? No problem:

from django.contrib.auth import get_user_model
from django.test import Client

client = Client()

user = get_user_model().objects.get(username="my-username")
client.force_login(user)

With that, you’re logged in and ready to make requests.

Here’s a quick example of a GET call:

from django.contrib.auth import get_user_model
from django.test import Client

client = Client()

user = get_user_model().objects.get(username="my-username")
client.force_login(user)

client.get("http://localhost:8000/my-endpoint")

Running into issues with host validation? Specify the server name explicitly:

from django.contrib.auth import get_user_model
from django.test import Client

client = Client()

user = get_user_model().objects.get(username="my-username")
client.force_login(user)

client.get("http://localhost:8000/my-endpoint", SERVER_NAME="localhost")

And that’s it: a direct way to play with Django endpoints in your local environment.

Copyright © 2025 Niccolò Mineo
Some rights reserved: CC BY-NC 4.0