A template directory is a filesystem location where Django looks for HTML templates such as news.html. You can keep templates beside their apps or collect project HTML in one shared directory; reusable apps should ship their own templates. section 3.6
Configure and use a project-level template directory by:
- Creating RiffMates/templates/news.html. section 3.6
- Setting TEMPLATES['DIRS'] to [BASE_DIR / 'templates'] in settings.py. section 3.6
- Returning render(request, "news.html", data) from the news view, then visiting /news/. section 3.6
RiffMates news page
Django finds news.html in the configured directory, renders its {% for %} loop with the news context, and produces a list of news items. section 3.6
Listing 3.7 The new templates directory and the soon-to-be-created news.html
RiffMates/
├── RiffMates
│ ├── __init__.py
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── home
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── manage.py
└── templates
└── news.html
Use the project tree to locate the shared templates directory and its news.html file. section 3.6
