[Answered ]-Template File not found

1πŸ‘

βœ…

Your templates folder should be within your app folder home (under about), otherwise Django won’t find it. Check out https://django-project-skeleton.readthedocs.io/en/latest/structure.html for the proper file structure. My guess is the same could be said for the other folders withing your templates folder. You can have a templates folder in your root, but I don’t think this is what you will need in your case.

To create a global template, you can have a template folder in your root β€˜testWebsite’ directory like you already have. Then in your settings.py do the following:

# settings.py

TEMPLATES = [
    {
        ...
        'DIRS': [str(BASE_DIR.joinpath('templates'))],
        ...
    },
]

What I usually do is create a base.html in each app, then in each of your html pages within the app you can add a line like {% extends "home/base.html" %}. And in each of your base.html files add {% extends "base.html" %}

Something like this (I didn’t include all the files, just a sample):

testWebsite
β”œβ”€β”€ about
β”‚   └── templates
β”‚       └── about
β”‚           β”œβ”€β”€ base.html
β”‚           └── about.html
β”œβ”€β”€ home
β”‚   └── templates
β”‚       └── home
β”‚           β”œβ”€β”€ base.html
β”‚           β”œβ”€β”€ greet.html
β”‚           └── index.html
β”œβ”€β”€ project_long_page
β”‚   └── templates
β”‚       └── project_long_page
β”‚           β”œβ”€β”€ base.html
β”‚           └── project_long_page.html
β”œβ”€β”€ templates
β”‚   └── base.html
└── testWebsite
    └── settings.py
πŸ‘€raphael

Leave a comment