Opened 12 years ago

Last modified 12 years ago

#18697 closed Bug

django.contrib.admin.AdminSite should not pass a sequence as the template to TemplateResponse — at Version 4

Reported by: and@… Owned by: Travis Swicegood
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 Morales)

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 sites.py{.orig,}
--- sites.py.orig	2012-03-23 12:59:19.000000000 -0400
+++ sites.py	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, current_app=self.name)
+            context, current_app=self.name)
 
     def app_index(self, request, app_label, extra_context=None):
         user = request.user

Change History (4)

comment:1 by and@…, 12 years ago

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 by Travis Swicegood, 12 years ago

Cc: travis@… added
Needs tests: set
Owner: changed from nobody to Travis Swicegood
Triage Stage: UnreviewedAccepted

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 by and@…, 12 years ago

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.

Antony

comment:4 by Ramiro Morales, 12 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top