How It Works Features Pricing Blog Error Guides
Log In Start Free Trial
Django · Python

Fix TemplateDoesNotExist: TemplateDoesNotExist at /dashboard/ — dashboard/index.html in Django

This error means Django cannot find the specified template file in any of its configured template directories. Fix it by verifying the TEMPLATES setting includes your app's directories, ensuring APP_DIRS is True, and checking that the template file path matches the string passed to render() exactly, including subdirectory names.

Reading the Stack Trace

Traceback (most recent call last): File "/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/app/dashboard/views.py", line 8, in index return render(request, 'dashboard/index.html') File "/venv/lib/python3.11/site-packages/django/shortcuts.py", line 24, in render content = loader.render_to_string(template_name, context, request, using=using) File "/venv/lib/python3.11/site-packages/django/template/loader.py", line 61, in render_to_string template = get_template(template_name, using=using) File "/venv/lib/python3.11/site-packages/django/template/loader.py", line 19, in get_template raise TemplateDoesNotExist(template_name, chain=chain) django.template.exceptions.TemplateDoesNotExist: dashboard/index.html

Here's what each line means:

Common Causes

1. APP_DIRS not enabled

The TEMPLATES setting has APP_DIRS set to False, so Django does not search inside each app's templates/ directory.

# settings.py
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': False,  # Templates inside apps are not discovered
        'OPTIONS': { ... },
    },
]

2. Template in wrong directory structure

The template file exists but is not inside the expected app_name/templates/app_name/ subdirectory.

# File is at dashboard/index.html instead of dashboard/templates/dashboard/index.html
# views.py
def index(request):
    return render(request, 'dashboard/index.html')

3. App not in INSTALLED_APPS

The app containing the template is not registered in INSTALLED_APPS, so Django's app-directory loader skips it.

# settings.py
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    # 'dashboard',  # Missing!
]

The Fix

Place the template at dashboard/templates/dashboard/index.html so Django's app-directory loader can find it. Enable APP_DIRS and add the app to INSTALLED_APPS. The double directory naming (dashboard/templates/dashboard/) is a Django convention to namespace templates.

Before (broken)
# dashboard/views.py
def index(request):
    return render(request, 'dashboard/index.html')

# Template file located at: dashboard/index.html  (WRONG)
After (fixed)
# 1. Move template to correct location:
#    dashboard/templates/dashboard/index.html

# 2. Ensure app is in INSTALLED_APPS:
# settings.py
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'dashboard',  # Added
]

# 3. Ensure APP_DIRS is True:
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],
        'APP_DIRS': True,
        'OPTIONS': { ... },
    },
]

Testing the Fix

import pytest
from django.test import TestCase, Client


class TestDashboardTemplate(TestCase):
    def setUp(self):
        self.client = Client()

    def test_dashboard_index_renders(self):
        response = self.client.get('/dashboard/')
        assert response.status_code == 200
        self.assertTemplateUsed(response, 'dashboard/index.html')

    def test_dashboard_index_contains_expected_content(self):
        response = self.client.get('/dashboard/')
        assert response.status_code == 200
        self.assertContains(response, '<div')

    def test_template_exists(self):
        from django.template.loader import get_template
        template = get_template('dashboard/index.html')
        assert template is not None

Run your tests:

pytest

Pushing Through CI/CD

git checkout -b fix/template-not-found-dashboard,git add dashboard/templates/dashboard/index.html settings.py,git commit -m "fix: move template to correct directory and enable APP_DIRS",git push origin fix/template-not-found-dashboard

Your CI config should look something like this:

name: CI
on:
  pull_request:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
          cache: 'pip'
      - run: pip install -r requirements.txt
      - run: python manage.py check --deploy
      - run: pytest --tb=short -q

The Full Manual Process: 18 Steps

Here's every step you just went through to fix this one bug:

  1. Notice the error alert or see it in your monitoring tool
  2. Open the error dashboard and read the stack trace
  3. Identify the file and line number from the stack trace
  4. Open your IDE and navigate to the file
  5. Read the surrounding code to understand context
  6. Reproduce the error locally
  7. Identify the root cause
  8. Write the fix
  9. Run the test suite locally
  10. Fix any failing tests
  11. Write new tests covering the edge case
  12. Run the full test suite again
  13. Create a new git branch
  14. Commit and push your changes
  15. Open a pull request
  16. Wait for code review
  17. Merge and deploy to production
  18. Monitor production to confirm the error is resolved

Total time: 30-60 minutes. For one bug.

Or Let bugstack Fix It in Under 2 minutes

Every step above? bugstack does it automatically.

Step 1: Install the SDK

pip install bugstack

Step 2: Initialize

import bugstack

bugstack.init(api_key=os.environ["BUGSTACK_API_KEY"])

Step 3: There is no step 3.

bugstack handles everything from here:

  1. Captures the stack trace and request context
  2. Pulls the relevant source files from your GitHub repo
  3. Analyzes the error and understands the code context
  4. Generates a minimal, verified fix
  5. Runs your existing test suite
  6. Pushes through your CI/CD pipeline
  7. Deploys to production (or opens a PR for review)

Time from error to fix deployed: Under 2 minutes.

Human involvement: zero.

Try bugstack Free →

No credit card. 5-minute setup. Cancel anytime.

Deploying the Fix (Manual Path)

  1. Run the full test suite locally to confirm the template renders.
  2. Open a pull request with the template relocation and settings change.
  3. Wait for CI checks to pass on the PR.
  4. Have a teammate review and approve the PR.
  5. Merge to main and verify the deployment in staging before promoting to production.

Frequently Asked Questions

BugStack runs the fix through your existing test suite, generates additional template-rendering tests, and validates that all views return 200 before marking it safe to deploy.

BugStack never pushes directly to production. Every fix goes through a pull request with full CI checks, so your team can review it before merging.

The dashboard/templates/dashboard/ pattern namespaces templates so that two apps with an index.html do not collide. Without it, Django may load the wrong app's template.

Yes. Add the directory to the DIRS list in TEMPLATES. For example: 'DIRS': [BASE_DIR / 'templates']. This is common for project-wide base templates.