mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Avoided exceptions in admindocs' template detail view.
This is marginally better than crashing when several Django template engines are configured in a project. Refs #24125.
This commit is contained in:
		| @@ -8,7 +8,7 @@ from django.conf import settings | |||||||
| from django.contrib import admin | from django.contrib import admin | ||||||
| from django.contrib.admin.views.decorators import staff_member_required | from django.contrib.admin.views.decorators import staff_member_required | ||||||
| from django.db import models | from django.db import models | ||||||
| from django.core.exceptions import ViewDoesNotExist | from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist | ||||||
| from django.http import Http404 | from django.http import Http404 | ||||||
| from django.core import urlresolvers | from django.core import urlresolvers | ||||||
| from django.contrib.admindocs import utils | from django.contrib.admindocs import utils | ||||||
| @@ -293,14 +293,21 @@ class TemplateDetailView(BaseAdminDocsView): | |||||||
|     def get_context_data(self, **kwargs): |     def get_context_data(self, **kwargs): | ||||||
|         template = self.kwargs['template'] |         template = self.kwargs['template'] | ||||||
|         templates = [] |         templates = [] | ||||||
|         for dir in Engine.get_default().dirs: |         try: | ||||||
|             template_file = os.path.join(dir, template) |             default_engine = Engine.get_default() | ||||||
|             templates.append({ |         except ImproperlyConfigured: | ||||||
|                 'file': template_file, |             # Non-trivial TEMPLATES settings aren't supported (#24125). | ||||||
|                 'exists': os.path.exists(template_file), |             pass | ||||||
|                 'contents': lambda: open(template_file).read() if os.path.exists(template_file) else '', |         else: | ||||||
|                 'order': list(Engine.get_default().dirs).index(dir), |             # This doesn't account for template loaders (#24128). | ||||||
|             }) |             for index, directory in enumerate(default_engine.dirs): | ||||||
|  |                 template_file = os.path.join(directory, template) | ||||||
|  |                 templates.append({ | ||||||
|  |                     'file': template_file, | ||||||
|  |                     'exists': os.path.exists(template_file), | ||||||
|  |                     'contents': lambda: open(template_file).read() if os.path.exists(template_file) else '', | ||||||
|  |                     'order': index, | ||||||
|  |                 }) | ||||||
|         kwargs.update({ |         kwargs.update({ | ||||||
|             'name': template, |             'name': template, | ||||||
|             'templates': templates, |             'templates': templates, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user