6

I would like to create a custom index.html derived from the admin/index.html individual for each app in my django project.

For instance my folder structure is like:

  • app1
    • templates
      • index.html (different from the global template admin/index.html)
  • app2
  • templates
    • admin
      • base.html
      • index.html (global template index.html)

How can I achieve custom admin index.html files for my apps, that are recognized by django? For the moment only the index.html in the global template/admin folder is considered for rendering the index pages in my backend.

I'm using django 1.6

BlueSapphire
  • 311
  • 6
  • 18

1 Answers1

6

Unfortunately, only certain parts of the Django admin site can be overridden on a per-app basis, as it says in the documentation:

Not every template in contrib/admin/templates/admin may be overridden per app or per model. The following can:

  • app_index.html
  • change_form.html
  • change_list.html
  • delete_confirmation.html
  • object_history.html

Remember that the admin interface is itself and app, so it's going to do a single template sweep and load the first set of templates that comes up.

I think your two best bets are either to use multiple admin sites in your project or to add a custom view for specific apps -- the former is probably easier, but will be a problem if you don't want people to have to login separately to control certain things.

Jager567
  • 617
  • 4
  • 10
MBrizzle
  • 1,783
  • 1
  • 18
  • 31
  • Even by using modifiable templates in my apps it is pretty odd, that for instance a admin-template in app1 is not considdered if the entry for the template directory in TEMPLATE_DIRS is listed after the template directory of app2. Django does not seem to distinguish between the apps by rendering admin templates at all, or am I wrong here? – BlueSapphire Mar 26 '14 at 14:57
  • This could be due to a few things. First, you need to make sure that the template is in an admin folder, like app1/templates/admin/index.html, whereas those templates for the app itself should be app1/templates/app1/whatever_template. Like any other app, the django admin interface is going to look for a namespaced folder, and skip over anything that isn't properly namespaced. – MBrizzle Mar 26 '14 at 15:04
  • I'm confused. The namespacing for admin does not seem to work for me. If I apply my structure like: - app1/templates/admin/app_index.html - app2/templates/admin/app_index.html does not seem to work. So neither the app2/templates/admin/app_index.html nor app/.../app_index.html does not seem to be considered. – BlueSapphire Mar 27 '14 at 08:50
  • 1
    Ok, I see now, that ALL my app-Admin changes have to be in the global templates/admin/( app1 | app2 )/ directory to work for each app. – BlueSapphire Mar 27 '14 at 09:09