Serve a Client Side Application from Django

Django has built-in support for view templates which can be used to serve a client application. To keep things organized, create a client directory in the root of your project, next to main.py and the core module directory. Add a simple HTML file to act as a test template.

Next we'll update the core settings of the application, adding BASE_DIR (defined during project setup) to the list of template directories.

TEMPLATES = [
    {
        ...,
        'DIRS': [BASE_DIR],

To support the loading of static assets you should also add client as a directory from which static files can be served. Add this to the bottom of your settings file.

STATICFILES_DIRS = [
    BASE_DIR / "client",
]

Lastly, configure the application to serve the HTML file by editing urls.py. Below, the HTML will be served from the application root.

from django.urls import path
from django.shortcuts import render
from django.urls import path

def client(request):
    return render(request, 'client/index.html')

urlpatterns = [
    path('', client),
]