mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #33473 -- Fixed detecting changes by autoreloader in .py files inside template directories.
This commit is contained in:
parent
c5cd878382
commit
832adb31f2
@ -48,6 +48,8 @@ def watch_for_template_changes(sender, **kwargs):
|
|||||||
|
|
||||||
@receiver(file_changed, dispatch_uid='template_loaders_file_changed')
|
@receiver(file_changed, dispatch_uid='template_loaders_file_changed')
|
||||||
def template_changed(sender, file_path, **kwargs):
|
def template_changed(sender, file_path, **kwargs):
|
||||||
|
if file_path.suffix == '.py':
|
||||||
|
return
|
||||||
for template_dir in get_template_directories():
|
for template_dir in get_template_directories():
|
||||||
if template_dir in file_path.parents:
|
if template_dir in file_path.parents:
|
||||||
reset_loaders()
|
reset_loaders()
|
||||||
|
@ -39,6 +39,19 @@ class TemplateReloadTests(SimpleTestCase):
|
|||||||
self.assertIsNone(autoreload.template_changed(None, Path(__file__)))
|
self.assertIsNone(autoreload.template_changed(None, Path(__file__)))
|
||||||
mock_reset.assert_not_called()
|
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):
|
def test_watch_for_template_changes(self):
|
||||||
mock_reloader = mock.MagicMock()
|
mock_reloader = mock.MagicMock()
|
||||||
autoreload.watch_for_template_changes(mock_reloader)
|
autoreload.watch_for_template_changes(mock_reloader)
|
||||||
|
Loading…
Reference in New Issue
Block a user