1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #27020 -- Used a context manager to close files.

This commit is contained in:
Ville Skyttä
2016-08-05 02:45:14 +03:00
committed by Tim Graham
parent 50e299dbfb
commit a2fb2b3a1f
5 changed files with 21 additions and 21 deletions

View File

@@ -324,10 +324,15 @@ class TemplateDetailView(BaseAdminDocsView):
# This doesn't account for template loaders (#24128).
for index, directory in enumerate(default_engine.dirs):
template_file = os.path.join(directory, template)
if os.path.exists(template_file):
with open(template_file) as f:
template_contents = f.read()
else:
template_contents = ''
templates.append({
'file': template_file,
'exists': os.path.exists(template_file),
'contents': lambda: open(template_file).read() if os.path.exists(template_file) else '',
'contents': template_contents,
'order': index,
})
kwargs.update({