Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#12292 closed (wontfix)

render_to_response method on AdminSite and ModelAdmin

Reported by: LeafStorm Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I have written a patch against trunk to add a render_to_response method to AdminSite and ModelAdmin. The method replaces the

context_instance = template.RequestContext(request,
return render_to_response(templates, context, context_instance=context_instance)

idiom at the end of admin views with:

return self.render_to_response(request, templates, context)

This may seem like a small change, but it allows the method in which admin templates are rendered to be overridden. This can be used to inject extra values into the context for customized templates, or to possibly replace the Django template language with an external template language like Jinja2 or Mako in the admin ("loose coupling"). It also reduces the boilerplate in the admin and makes it easier to upgrade in the event that the template API changes ("don't repeat yourself").

The included patch includes documentation updates, but no code outside the admin has been changed (so the rest of the trunk may need updating to use the new method). All admin-related tests have been run on the patch, and it is very unlikely to break backwards compatibility, due to the fact that it merely places the code that was used before in another place.

Attachments (1)

admin-render-to-response.diff (9.5 KB) - added by LeafStorm 9 years ago.

Download all attachments as: .zip

Change History (3)

Changed 9 years ago by LeafStorm

comment:1 Changed 9 years ago by Russell Keith-Magee

Resolution: wontfix
Status: newclosed

I'm marking this wontfix. I'm not rejecting the idea of using non-Django template languages - just suggesting that there is a better way. Specifically, #6262/r11862 should make it possible to write a Jinja/Mako template loader without needing any changes to Django core. The process for using non-Django template languages is documented in abstract terms, but the abstract example should map fairly closely to the Jinja experience:

comment:2 Changed 9 years ago by Nick Sandford

I kind of saw it as a neat way to add some extra context to a ModelAdmin..

you could do:

class FooAdmin(admin.ModelAdmin):
    def render_to_response(request, template, context):
        context.update({'foo': 'bar'})
        return super(FooAdmin, self).render_to_response(request, template, context)
Note: See TracTickets for help on using tickets.
Back to Top