Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom django admin template for app

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

like image 660
BlueSapphire Avatar asked Mar 26 '14 13:03

BlueSapphire


People also ask

Can we customize Django admin template?

The Django admin is a powerful built-in tool giving you the ability to create, update, and delete objects in your database using a web interface. You can customize the Django admin to do almost anything you want.

How do I get Django admin template?

To view the default admin template you can access it in the django/contrib/admin/templates/admin folder. In this situation you will most likely be using a virtual environment and can find this folder in the directory that contains all the installed libraries.

Can I use Django admin as frontend?

Django Admin is one of the most important tools of Django. It's a full-fledged application with all the utilities a developer need. Django Admin's task is to provide an interface to the admin of the web project. Django's Docs clearly state that Django Admin is not made for frontend work.


1 Answers

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.

like image 162
MBrizzle Avatar answered Oct 14 '22 07:10

MBrizzle