# Django is loading templates from a wrong directory

**URL:** <https://forum.djangoproject.com/t/django-is-loading-templates-from-a-wrong-directory/1721>\
**Category:** Using Django\
**Created:** [March 29, 2020, 8:21pm UTC](https://forum.djangoproject.com/t/django-is-loading-templates-from-a-wrong-directory/1721 "2020-03-29T20:21:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![FenryrMKIII](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/fenryrmkiii/32/933_2.png) [@FenryrMKIII](https://forum.djangoproject.com/u/FenryrMKIII)\
**Post date:** [March 29, 2020, 8:21pm UTC](https://forum.djangoproject.com/t/django-is-loading-templates-from-a-wrong-directory/1721/1 "2020-03-29T20:21:36Z")

</div>

Hello,

I am trying to set a root directory for my templates on top of the app directories. The idea would be to have a base directory from which apps can extend the templates as desired.

Here is my templates settings in _project\_name/project\_name/settings.py_ :

```
TEMPLATES = [

    {

        'BACKEND': 'django.template.backends.django.DjangoTemplates',

        'DIRS': [],

        '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',

            ],

        },

    },

]

```

when looking at the template loading, I see in the error message that django is trying to load templates from :

_c:\Users\User\project\_name\app\_name\templates\project\_name\base.html (Source does not exist)_

i don’t undersand the second _project\_name_ because it shoud be _app\_name_. I checked, the app in question has a name defined in its _apps.py_. Any idea what I am doing wrong ?

---

<div class="post-metadata">

**Author:** ![timonweb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/timonweb/32/570_2.png) [@timonweb](https://forum.djangoproject.com/u/timonweb)\
**Post date:** [March 30, 2020, 9:38am UTC](https://forum.djangoproject.com/t/django-is-loading-templates-from-a-wrong-directory/1721/2 "2020-03-30T09:38:45Z")

</div>

For that “root directory” to work, you need to set it within “DIRS” list, something like:

```python

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath( __file__ )))

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, "templates")], # This should produce a "c:\Users\User\project_name\templates" path
        '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',
            ],
        },
    },
]

```

---

<div class="post-metadata">

**Author:** ![FenryrMKIII](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/fenryrmkiii/32/933_2.png) [@FenryrMKIII](https://forum.djangoproject.com/u/FenryrMKIII)\
**Post date:** [March 30, 2020, 9:52am UTC](https://forum.djangoproject.com/t/django-is-loading-templates-from-a-wrong-directory/1721/3 "2020-03-30T09:52:58Z")

</div>

Hello,

Thanks for the answer. Indeed, I need this.

But at the moment, I first want to understand why django is calling a directory called “project\_name” for my “app\_name” rather than “app\_name” as foreseen :

```
c:\Users\User\project_name\app_name\templates\ **project\_name** \base.html
```

should be

```
c:\Users\User\project_name\app_name\templates\ **app\_name** \base.html
```

---

<div class="post-metadata">

**Author:** ![timonweb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/timonweb/32/570_2.png) [@timonweb](https://forum.djangoproject.com/u/timonweb)\
**Post date:** [March 30, 2020, 11:29am UTC](https://forum.djangoproject.com/t/django-is-loading-templates-from-a-wrong-directory/1721/4 "2020-03-30T11:29:28Z")

</div>

Calling from where? Please show how you’re trying to load a template.

---

<div class="post-metadata">

**Author:** ![FenryrMKIII](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/fenryrmkiii/32/933_2.png) [@FenryrMKIII](https://forum.djangoproject.com/u/FenryrMKIII)\
**Post date:** [March 30, 2020, 11:33am UTC](https://forum.djangoproject.com/t/django-is-loading-templates-from-a-wrong-directory/1721/5 "2020-03-30T11:33:53Z")

</div>

from project\_name/app\_name/views.py :

```
class myView(ListView):

    [...]

    template_name = "app_name/index.html"
```

---

<div class="post-metadata">

**Author:** ![timonweb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/timonweb/32/570_2.png) [@timonweb](https://forum.djangoproject.com/u/timonweb)\
**Post date:** [March 30, 2020, 11:35am UTC](https://forum.djangoproject.com/t/django-is-loading-templates-from-a-wrong-directory/1721/6 "2020-03-30T11:35:46Z")

</div>

Ok, but your error is about “base.html”, so I assume your `index.html` file should have the `{% extend ... %}` tag at the top, could you show it?

---

<div class="post-metadata">

**Author:** ![FenryrMKIII](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/fenryrmkiii/32/933_2.png) [@FenryrMKIII](https://forum.djangoproject.com/u/FenryrMKIII)\
**Post date:** [March 30, 2020, 12:01pm UTC](https://forum.djangoproject.com/t/django-is-loading-templates-from-a-wrong-directory/1721/7 "2020-03-30T12:01:41Z")

</div>

You are correct. The issue must come from there :

{% extends “project\_name/base.html” %}

---

<div class="post-metadata">

**Author:** ![timonweb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/timonweb/32/570_2.png) [@timonweb](https://forum.djangoproject.com/u/timonweb)\
**Post date:** [March 30, 2020, 12:26pm UTC](https://forum.djangoproject.com/t/django-is-loading-templates-from-a-wrong-directory/1721/8 "2020-03-30T12:26:10Z")

</div>

So here you are, in your case, `project_name/base.html` tells Django that `project_name` is the name of the app, that’s why it looks for a template at: `c:\Users\User\project_name\app_name\templates\project_name\base.html`.

You don’t need to use a `project_name` in a template path. If you want to load a template file from the top level directory i.e. root, just call it by its name:

`{% extends “base.html” %}`

Hope this helps

---

<div class="post-metadata">

**Author:** ![FenryrMKIII](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/fenryrmkiii/32/933_2.png) [@FenryrMKIII](https://forum.djangoproject.com/u/FenryrMKIII)\
**Post date:** [March 30, 2020, 12:27pm UTC](https://forum.djangoproject.com/t/django-is-loading-templates-from-a-wrong-directory/1721/9 "2020-03-30T12:27:50Z")

</div>

It’s right on spot. Thank you very much for your help and your time !

---

<div class="post-metadata">

**Author:** ![timonweb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/timonweb/32/570_2.png) [@timonweb](https://forum.djangoproject.com/u/timonweb)\
**Post date:** [March 30, 2020, 1:24pm UTC](https://forum.djangoproject.com/t/django-is-loading-templates-from-a-wrong-directory/1721/10 "2020-03-30T13:24:40Z")

</div>

no problem, you’re welcome!
