Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#18697 closed Bug (fixed)

django.contrib.admin.AdminSite should not pass a sequence as the template to TemplateResponse

Reported by: and@… Owned by: tswicegood
Component: contrib.admin Version: 1.4
Severity: Normal Keywords:
Cc: travis@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by ramiro)

This appears to be a simple coding error.

I have code (mobile-admin) that sets index_template to ['admin/index.html', 'index.html']. The current call ends up passing [['admin/index.html', 'index.html']] to TemplateResponse, which fails with a TypeError trying to use ['admin/index.html', 'index.html'] as a template.

The following patch fixes this issue:

root@host:/usr/share/pyshared/django/contrib/admin# diff -uw{.orig,}
---	2012-03-23 12:59:19.000000000 -0400
+++	2012-08-01 18:18:55.000000000 -0400
@@ -381,9 +381,9 @@
             'app_list': app_list,
         context.update(extra_context or {})
-        return TemplateResponse(request, [
+        return TemplateResponse(request,
             self.index_template or 'admin/index.html',
-        ], context,
+            context,
     def app_index(self, request, app_label, extra_context=None):
         user = request.user

Change History (6)

comment:1 Changed 3 years ago by and@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Just wanted to mention that I didn't properly escape the description of the problem and doubled square braces don't show properly.

comment:2 Changed 2 years ago by tswicegood

  • Cc travis@… added
  • Needs tests set
  • Owner changed from nobody to tswicegood
  • Triage Stage changed from Unreviewed to Accepted

Thanks for reporting this. Definitely should be fixed. I think the correct way to go about this is to verify the type of self.index_template so we can make sure that string-style values also work.

comment:3 Changed 2 years ago by and@…

You would know better than I what's needed to make the fix robust. I didn't want to leave my patch only for me, but I don't think I know enough to do more than send it along in the hopes that someone like you does :-)

I'd be happy to test a patch in my environment once you've got one in place, if that would help.


comment:4 Changed 2 years ago by ramiro

  • Description modified (diff)

comment:5 Changed 2 years ago by Ramiro Morales <cramm0@…>

  • Resolution set to fixed
  • Status changed from new to closed

In b64d30405a3d5468dc8c6232747d45bbeee4f7bb:

Fixed #18697 -- Made values accepted for two customizable admin templates consistent.

Thanks and at cloverfastfood dot com for the report.

comment:6 Changed 2 years ago by Ramiro Morales <cramm0@…>

In 6a098aa6f29b484254de50c4eb113bdbad1d7e78:

[1.5.x] Fixed #18697 -- Made values accepted for two customizable admin templates consistent.

Thanks and at cloverfastfood dot com for the report.

b64d30405a3d5468dc8c6232747d45bbeee4f7bb from master.

Note: See TracTickets for help on using tickets.
Back to Top