# TemplateDoesNotExist at /store/home.html

**URL:** <https://forum.djangoproject.com/t/templatedoesnotexist-at-store-home-html/14668>\
**Category:** Templates & Frontend\
**Created:** [July 7, 2022, 10:53am UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-store-home-html/14668 "2022-07-07T10:53:49Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhi108](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/abhi108/32/9175_2.png) [@Abhi108](https://forum.djangoproject.com/u/Abhi108)\
**Post date:** [July 7, 2022, 10:53am UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-store-home-html/14668/1 "2022-07-07T10:53:49Z")

</div>

Hi, I’m using Django Version: 4.0.6 and Python Version: 3.10.5 on windows 10  
I am getting the “TemplateDoesNotExist” error and trying to resolve it since past 2 days.  
I have added the path for templates folder.

‘DIRS’: [os.path.join(BASE\_DIR, ‘templates’)],

Because this didn’t work I also created another templates folder inside the app. and I’m still getting the same error.

I have used the following lines in the views.py

return render(request, ‘store/home.html’, {‘products’ : products})

I have recently started learning Django and this is getting frustrating. Please need some help. Below is the error message

## Template-loader postmortem

Django tried loading these templates, in this order:

Using engine `django`:

- `django.template.loaders.filesystem.Loader`: D:\ecommerce\store\home.html (Source does not exist)
- `django.template.loaders.filesystem.Loader`: D:\templates\store\home.html (Source does not exist)
- `django.template.loaders.app_directories.Loader`: D:\ecommerce\venv\lib\site-packages\django\contrib\admin\templates\store\home.html (Source does not exist)
- `django.template.loaders.app_directories.Loader`: D:\ecommerce\venv\lib\site-packages\django\contrib\auth\templates\store\home.html (Source does not exist)

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 7, 2022, 11:37am UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-store-home-html/14668/2 "2022-07-07T11:37:21Z")

</div>

The template loader message is telling you where it’s looking.

Where do you have this `home.html` template?

What is your complete `TEMPLATES` setting?

In what view does this line of code appear? (Please include the complete path)

> [@Abhi108](#):
>
> `return render(request, ‘store/home.html’, {‘products’ : products})`

Also, when posting code, templates, or error messages here, surround each block of code (or template, or error message) between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep that text properly formatted, which is critical with Python.

---

<div class="post-metadata">

**Author:** ![Abhi108](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/abhi108/32/9175_2.png) [@Abhi108](https://forum.djangoproject.com/u/Abhi108)\
**Post date:** [July 7, 2022, 12:24pm UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-store-home-html/14668/3 "2022-07-07T12:24:30Z")

</div>

Thank you for the reply sir,

1. Initially I had `home.html` at the Project level (where the templates of all the apps are stored)

````nohighlight
    | |-templates(same level as manage.py, project, app, venv)
    | | |-app_name(store)
    | | | |-home.html ```

  Because I was getting the ```Template Does not exist error``` I shifted the ```templates directory``` inside the ```app folder``` as shown below:

```|-app_name(store)
   | |-templates
   | | |-app_name(store)
   | | | |-home.html ```

I also tried having both simultaneously.

 2) Below is the template list in my settings.py file(I thought that was the 'Template Settings' you are referring to.

``` TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')], #I also tried 'DIRS' : [BASE_DIR, '/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',
            ],
        },
    },
] ```

  3) The 'views.py' is in my app named 'store'

```ECOMMERCE
    | |-core(project_name)
    | |-store(app_name)
    | | |-views.py ```

Below is the content of 'views.py'

````

from django.shortcuts import render  
from .models import Category, Product

 ![sample](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/e/eca75d34cc6d1e9f1355e04f8b1328ae7cae07ff.jpeg)

def all\_products(request):  
products = Product.objects.all()  
return render(request, ‘store/home.html’, {‘products’ : products})```  
Thank you!

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 7, 2022, 2:29pm UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-store-home-html/14668/4 "2022-07-07T14:29:51Z")

</div>

It looks like from the diagram that home.html is in the `templates` directory and not the `store/templates` directory. (At least your image doesn’t show what’s in the `store` directories.) What’s in those `store` directories?

(Side note: The three backtick characters must be lines by themselves, not part of the lines of code.)

---

<div class="post-metadata">

**Author:** ![Abhi108](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/abhi108/32/9175_2.png) [@Abhi108](https://forum.djangoproject.com/u/Abhi108)\
**Post date:** [July 7, 2022, 3:47pm UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-store-home-html/14668/5 "2022-07-07T15:47:37Z")

</div>

Sir, I learnt from an article that there are two ways of letting Django know where it has to look for the template.  
a) By creating the ‘templates’ folder inside the particular ‘app directory’ and ensure that the ‘template files’ are placed in a directory with same name as the ‘app name’(inside the ‘templates’ dir). This I have marked as ‘a’ in the image shared.  
b) By creating the Project level ‘templates’ directory and inside this directory create sub directory with same name as the concerned ‘App’. Inside the app\_named directory lies your ‘template files’. In this image shared below this is marked as ‘b’.

I got error in both the methods so I left them as it is till I get rid of the error. Please correct me if I am wrong in my understanding of what I have mentioned.

‘core’ is the name of my project and ‘store’ is the name of the app I created.

 ![sample](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/d/d9d7b0dfc3b6f54cf7bb4ee3fc6841a9ade8cc4d.jpeg)

> [@KenWhitesell](#):
>
> (Side note: The three backtick characters must be lines by themselves, not part of the lines of code.)

Thank you.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 7, 2022, 4:15pm UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-store-home-html/14668/6 "2022-07-07T16:15:59Z")

</div>

What is your BASE\_DIR?

What is your INSTALLED\_APPS setting?

What is in your `store/apps.py` file?

> [@Abhi108](#):
>
> a) By creating the ‘templates’ folder inside the particular ‘app directory’ and ensure that the ‘template files’ are placed in a directory with same name as the ‘app name’(inside the ‘templates’ dir). This I have marked as ‘a’ in the image shared.

This relates to your `APPS_DIR` attribute of your `TEMPLATES` setting. This should work assuming all other related settings are correct. (You have proper contents in your `apps.py` file and your `INSTALLED_APPS` is referencing the proper class.)

> [@Abhi108](#):
>
> b) By creating the Project level ‘templates’ directory and inside this directory create sub directory with same name as the concerned ‘App’. Inside the app\_named directory lies your ‘template files’. In this image shared below this is marked as ‘b’.

This is the directory structure searched by the `DIRS` attribute of `TEMPLATES`

(Side note on the directory names. They don’t _need_ to match the app in which they’re placed. They can match _any_ installed app name. That’s how an application can override a template originally defined in a different app.)

The problem here is that the image you’ve posted isn’t clear as to what your directory structure actually is. The image leads me to believe that the `store` directory is _in_ the `core` directory and not at the same level as it, inside the `ECOMMERCE` directory.

Verify that your actual directory structure is as described in the post:

```auto
d:\ECOMMERCE
d:\ECOMMERCE\core
d:\ECOMMERCE\store
d:\ECOMMERCE\store\templates
d:\ECOMMERCE\store\templates\store
d:\ECOMMERCE\store\templates\store\home.html

```

and not:

```auto
d:\ECOMMERCE
d:\ECOMMERCE\core
d:\ECOMMERCE\core\store
d:\ECOMMERCE\core\store\templates
d:\ECOMMERCE\core\store\templates\store
d:\ECOMMERCE\core\store\templates\store\home.html

```

---

<div class="post-metadata">

**Author:** ![Abhi108](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/abhi108/32/9175_2.png) [@Abhi108](https://forum.djangoproject.com/u/Abhi108)\
**Post date:** [July 7, 2022, 4:44pm UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-store-home-html/14668/7 "2022-07-07T16:44:17Z")

</div>

> [@KenWhitesell](#):
>
> What is your BASE\_DIR?

My “BASE\_DIR” is ‘ECOMMERCE’

```auto
BASE_DIR = Path( __file__ ).resolve().parent.parent

```

> [@KenWhitesell](#):
>
> What is your INSTALLED\_APPS setting?

```auto
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'store',
]

```

> [@KenWhitesell](#):
>
> What is in your `store/apps.py` file?

```auto
from django.apps import AppConfig

class StoreConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'store'

```

> [@KenWhitesell](#):
>
> Verify that your actual directory structure is as described in the post:
> 
> ```auto
> d:\ECOMMERCE
> d:\ECOMMERCE\core
> d:\ECOMMERCE\store
> d:\ECOMMERCE\store\templates
> d:\ECOMMERCE\store\templates\store
> d:\ECOMMERCE\store\templates\store\home.html
> 
> ```

This is the actual directory structure among the two. Also, I have tried the one below:

```auto
d:\ECOMMERCE
d:\ECOMMERCE\core
d:\ECOMMERCE\store
d:\ECOMMERCE\templates
d:\ECOMMERCE\templates\store
d:\ECOMMERCE\store\templates\store\home.html

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 7, 2022, 5:17pm UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-store-home-html/14668/8 "2022-07-07T17:17:47Z")

</div>

I think there’s a chance your BASE\_DIR isn’t what you think it is.

Add a print statement after the BASE\_DIR line to verify it.

(Side note, in most of my projects, I just have `'DIRS': ['templates']` as the setting. But I do have a couple projects using the `os.path.join` function as well.)

You might also want to verify if the directory name is “ECOMMERCE” or “ecommerce”, and whether you’re running this on a file system where case-sensitivity is important.

Either way, there’s something really odd going on here.

It may be helpful at this point if you were to post your complete settings file.

Also, how are you running this? Are you running this from the command line or in PowerShell? Is your venv active when you run this?

---

<div class="post-metadata">

**Author:** ![Abhi108](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/abhi108/32/9175_2.png) [@Abhi108](https://forum.djangoproject.com/u/Abhi108)\
**Post date:** [July 7, 2022, 5:53pm UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-store-home-html/14668/9 "2022-07-07T17:53:46Z")

</div>

> [@KenWhitesell](#):
>
> I think there’s a chance your BASE\_DIR isn’t what you think it is.
> 
> Add a print statement after the BASE\_DIR line to verify it.

I got the following output using print statement:

```auto
D:\ecommerce

```

> [@KenWhitesell](#):
>
> You might also want to verify if the directory name is “ECOMMERCE” or “ecommerce”, and whether you’re running this on a file system where case-sensitivity is important.

The directory I created was “ECOMMERCE” but my “BASE\_DIR” shows “ecommerce". I’m using Windows 10 O.S which uses the default file system NTFS.

> [@KenWhitesell](#):
>
> Also, how are you running this? Are you running this from the command line or in PowerShell? Is your venv active when you run this?

I’m using VSCode and tried running on both command line and in PowerShell options available.

> [@KenWhitesell](#):
>
> It may be helpful at this point if you were to post your complete settings file.

```auto
from pathlib import Path
import os

BASE_DIR = Path( __file__ ).resolve().parent.parent

SECRET_KEY = 'django-insecure-6yc5(cv#n-)ihv*#k*g_)7#@92r!f5v)m(&k8%o**#j_b46yd9'

DEBUG = True

ALLOWED_HOSTS = ['127.0.0.1']

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'store',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'core.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR, '/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',
            ],
        },
    },
]

WSGI_APPLICATION = 'core.wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True

STATIC_URL = 'static/'

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

Thank you.
```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 7, 2022, 6:01pm UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-store-home-html/14668/10 "2022-07-07T18:01:18Z")

</div>

> [@Abhi108](#):
>
> ` 'DIRS': [BASE_DIR, '/templates'],`

Ok, this definitely isn’t right. You’re creating a list with two options - BASE\_DIR and ‘/templates’, neither one is the location of your template file.

It should _either_ be `['templates']` or `[os.path.join(BASE_DIR, 'templates')]`

> [@Abhi108](#):
>
> I’m using VSCode and tried running on both command line and in PowerShell options available.

Try running it from a separate command line window where you can verify that the correct directory is the current directory and that the right virtual env is active. There may be a configuration issue with your VS Code launch.json file.

---

<div class="post-metadata">

**Author:** ![Abhi108](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/abhi108/32/9175_2.png) [@Abhi108](https://forum.djangoproject.com/u/Abhi108)\
**Post date:** [July 7, 2022, 6:19pm UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-store-home-html/14668/11 "2022-07-07T18:19:28Z")

</div>

> [@KenWhitesell](#):
>
> Try running it from a separate command line window where you can verify that the correct directory is the current directory and that the right virtual env is active. There may be a configuration issue with your VS Code launch.json file.

Thank you sir, It is working now.  
The mistake was that ‘store’ was not containing the ‘home.html’. They were at the same level(meaning in the same folder).

Now I changed it as follows:

![sample2](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/7/77848984a297a58981ba4d19a9fa7d31856766be.jpeg)

Thank You for your valuable time Sir, I have learnt a lot from you. I hope I will be able to pass on the knowledge.  
Have a Nice Time.!!

---

<div class="post-metadata">

**Author:** ![Abhi108](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/abhi108/32/9175_2.png) [@Abhi108](https://forum.djangoproject.com/u/Abhi108)\
**Post date:** [July 7, 2022, 6:20pm UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-store-home-html/14668/12 "2022-07-07T18:20:13Z")

</div>

> [@Abhi108](#):
>
> Now I changed it as follows:

Earlier it was as below:

![sample](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/5/5aa91f66c63bd0033a6a008b905991e54ca76dad.jpeg)
