mirror of
https://github.com/django/django.git
synced 2024-11-29 22:56:46 +01: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:
parent
3bba4b420e
commit
511a53b314
@ -8,7 +8,7 @@ from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.contrib.admin.views.decorators import staff_member_required
|
||||
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.core import urlresolvers
|
||||
from django.contrib.admindocs import utils
|
||||
@ -293,13 +293,20 @@ class TemplateDetailView(BaseAdminDocsView):
|
||||
def get_context_data(self, **kwargs):
|
||||
template = self.kwargs['template']
|
||||
templates = []
|
||||
for dir in Engine.get_default().dirs:
|
||||
template_file = os.path.join(dir, template)
|
||||
try:
|
||||
default_engine = Engine.get_default()
|
||||
except ImproperlyConfigured:
|
||||
# Non-trivial TEMPLATES settings aren't supported (#24125).
|
||||
pass
|
||||
else:
|
||||
# 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': list(Engine.get_default().dirs).index(dir),
|
||||
'order': index,
|
||||
})
|
||||
kwargs.update({
|
||||
'name': template,
|
||||
|
Loading…
Reference in New Issue
Block a user