Skip to content

Commit

Permalink
Fixed #33473 -- Fixed detecting changes by autoreloader in .py files …
Browse files Browse the repository at this point in the history
…inside template directories.
  • Loading branch information
hrushikeshrv authored and felixxm committed Feb 3, 2022
1 parent c5cd878 commit 832adb3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions django/template/autoreload.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def watch_for_template_changes(sender, **kwargs):

@receiver(file_changed, dispatch_uid='template_loaders_file_changed')
def template_changed(sender, file_path, **kwargs):
if file_path.suffix == '.py':
return
for template_dir in get_template_directories():
if template_dir in file_path.parents:
reset_loaders()
Expand Down
13 changes: 13 additions & 0 deletions tests/template_tests/test_autoreloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ def test_non_template_changed(self, mock_reset):
self.assertIsNone(autoreload.template_changed(None, Path(__file__)))
mock_reset.assert_not_called()

@override_settings(
TEMPLATES=[
{
'DIRS': [ROOT],
'BACKEND': 'django.template.backends.django.DjangoTemplates',
}
]
)
@mock.patch('django.template.autoreload.reset_loaders')
def test_non_template_changed_in_template_directory(self, mock_reset):
self.assertIsNone(autoreload.template_changed(None, Path(__file__)))
mock_reset.assert_not_called()

def test_watch_for_template_changes(self):
mock_reloader = mock.MagicMock()
autoreload.watch_for_template_changes(mock_reloader)
Expand Down

0 comments on commit 832adb3

Please sign in to comment.