Django TemplateDoesNotExist error for Jinja2 template (dashboard.jinja) [duplicate]

I'm trying to use Jinja2 templates in my Django project, but I'm getting the following error when accessing the / (dashboard) page:

TemplateDoesNotExist at /
dashboard.jinja

My Setup:

Settings (app/settings.py) I have configured Jinja2 as the template backend:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.jinja2.Jinja2',
        "DIRS": [BASE_DIR / "core/templates"],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

Template Location (app/authentication/templates/dashboard.jinja)

{% extends 'core/layouts/main.html' %}

{% block title %}Dashboard | {% endblock %}

{% block content %}
<h2>Welcome, {{ user.name }}</h2>
<a href="{% url 'logout' %}">Logout</a>
{% endblock %}

View (app/authentication/views.py)

@login_required
def dashboard(request):
    return render(request, "dashboard.jinja", {"user": request.user})

Issue:

The file dashboard.jinja exists in app/authentication/templates/, but Django is unable to find it.

I'm not sure if my TEMPLATES settings are correct for Jinja2.

I expected render(request, "dashboard.jinja") to find the file, but it throws TemplateDoesNotExist.

What I’ve Tried:

Ensured the file exists in app/authentication/templates/. Checked that the TEMPLATES["DIRS"] path is correct (core/templates).

Tried moving dashboard.jinja to core/templates/ to see if it gets detected. Question:

How can I correctly configure Django to find my Jinja2 template inside app/authentication/templates/?

Do I need to modify TEMPLATES['DIRS'], or should I use a different approach?

Any help would be appreciated!

Вернуться на верх