#18697 closed Bug (fixed)
django.contrib.admin.AdminSite should not pass a sequence as the template to TemplateResponse
Reported by: | 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 )
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 (6)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Cc: | added |
---|---|
Needs tests: | set |
Owner: | changed from | to
Triage Stage: | Unreviewed → 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 by , 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 , 12 years ago
Description: | modified (diff) |
---|
comment:5 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Just wanted to mention that I didn't properly escape the description of the problem and doubled square braces don't show properly.