Skip to content

Commit

Permalink
Fix HTML templates not reloading in development
Browse files Browse the repository at this point in the history
This is due to Django 4.1+ caching templates by default in development,
this was in Django's changelog but I missed it.

Shout out to @jefftriplett for pointing me in this direction!
  • Loading branch information
nickjj committed Feb 18, 2023
1 parent b643159 commit f706a63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed

- Ensure Flake8, Black and isort all use 79 as the max line length
- HTML templates not reloading in development by using `loaders` in `src/config/setting.py`

## [0.9.0] - 2022-09-09

Expand Down
11 changes: 10 additions & 1 deletion src/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,27 @@

ROOT_URLCONF = "config.urls"

# Starting with Django 4.1+ we need to pick which template loaders to use
# based on our environment since 4.1+ will cache templates by default.
default_loaders = [
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
]

cached_loaders = [("django.template.loaders.cached.Loader", default_loaders)]

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(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",
],
"loaders": default_loaders if DEBUG else cached_loaders,
},
},
]
Expand Down

0 comments on commit f706a63

Please sign in to comment.