Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions django/template/loaders/cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import hashlib

from django.conf import settings
from django.template import TemplateDoesNotExist
from django.template.backends.django import copy_exception

Expand Down Expand Up @@ -40,6 +41,9 @@ def get_template(self, template_name, skip=None):
memory leak. Thus, unraised copies of the exceptions are cached and
copies of those copies are raised after they're fetched from the cache.
"""
if settings.DEBUG:
return super().get_template(template_name, skip)

key = self.cache_key(template_name, skip)
cached = self.get_template_cache.get(key)
if cached:
Expand Down
3 changes: 2 additions & 1 deletion docs/releases/3.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ Signals
Templates
~~~~~~~~~

* ...
* The :ref:`cached template loader<template-loaders>` no longer caches
templates when ``DEBUG=True``.

Tests
~~~~~
Expand Down
5 changes: 5 additions & 0 deletions tests/template_tests/test_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ def test_template_name_lazy_string(self):
"""
self.assertEqual(self.engine.template_loaders[0].cache_key(lazystr('template.html'), []), 'template.html')

@override_settings(DEBUG=True)
def test_debug_does_not_cache(self):
self.engine.get_template('index.html')
self.assertEqual(self.engine.template_loaders[0].get_template_cache, {})


class FileSystemLoaderTests(SimpleTestCase):

Expand Down