| 437 | | More |
|---|
| 438 | | ==== |
|---|
| 439 | | |
|---|
| 440 | | There's much more to come. This document is not finished. |
|---|
| | 437 | Customize the admin look and feel |
|---|
| | 438 | ================================= |
|---|
| | 439 | |
|---|
| | 440 | Clearly having "Django administration" and "mysite.com" at the top of each |
|---|
| | 441 | admin page is ridiculous. It's just placeholder text. |
|---|
| | 442 | |
|---|
| | 443 | That's easy to change, though, using Django's template system. |
|---|
| | 444 | |
|---|
| | 445 | Open your admin settings file and look at the ``TEMPLATE_DIRS`` setting. |
|---|
| | 446 | ``TEMPLATE_DIRS`` is a tuple of filesystem directories to check when loading |
|---|
| | 447 | Django templates. It's a search path. |
|---|
| | 448 | |
|---|
| | 449 | The ``django-admin.py startproject`` command automatically prepopulated |
|---|
| | 450 | this setting with the location of Django's default admin templates, according |
|---|
| | 451 | to where you have Django installed. But let's add an extra line to |
|---|
| | 452 | ``TEMPLATE_DIRS`` so that it checks a custom directory first, before checking |
|---|
| | 453 | the default admin template directory:: |
|---|
| | 454 | |
|---|
| | 455 | TEMPLATE_DIRS = ( |
|---|
| | 456 | "/home/mytemplates/admin", |
|---|
| | 457 | "/usr/lib/python2.3/site-packages/django/conf/admin_templates", |
|---|
| | 458 | ) |
|---|
| | 459 | |
|---|
| | 460 | Now copy the template ``base_site.html`` from within the default Django admin |
|---|
| | 461 | template directory, into ``/home/mytemplates/admin`` (or wherever you're |
|---|
| | 462 | putting your custom admin templates). Edit the file and replace the generic |
|---|
| | 463 | Django stuff with your own site's name as you see fit. |
|---|
| | 464 | |
|---|
| | 465 | Note that any of Django's default admin templates can be overridden. To |
|---|
| | 466 | override a template, just do the same thing you did with ``base_site.html`` -- |
|---|
| | 467 | copy it from the default directory into your custom directory, and make |
|---|
| | 468 | changes. |
|---|
| | 469 | |
|---|
| | 470 | Customize the admin index page |
|---|
| | 471 | ============================== |
|---|
| | 472 | |
|---|
| | 473 | On a similar note, you might want to customize the look and feel of the Django |
|---|
| | 474 | admin index page. |
|---|
| | 475 | |
|---|
| | 476 | By default, it displays all available apps, according to your ``INSTALLED_APPS`` |
|---|
| | 477 | setting. But the order in which it displays things is random, and you may want |
|---|
| | 478 | to make significant changes to the layout. After all, the index is probably the |
|---|
| | 479 | most important page of the admin, and it should be easy to use. |
|---|
| | 480 | |
|---|
| | 481 | The template to customize is ``index.html``. (Do the same as with |
|---|
| | 482 | ``base_site.html`` in the previous section -- copy it from the default directory |
|---|
| | 483 | to your custom template directory.) Edit the file, and you'll see it uses a |
|---|
| | 484 | template tag called ``{% get_admin_app_list as app_list %}``. That's the magic |
|---|
| | 485 | that retrieves every installed Django app. Instead of using that, you can |
|---|
| | 486 | hard-code links to object-specific admin pages in whatever way you think is |
|---|
| | 487 | best. |
|---|
| | 488 | |
|---|
| | 489 | Django offers another shortcut in this department. Run the command |
|---|
| | 490 | ``django-admin.py adminindex polls`` to get a chunk of template code for |
|---|
| | 491 | inclusion in the admin index template. It's a useful starting point. |
|---|
| | 492 | |
|---|
| | 493 | Coming soon |
|---|
| | 494 | =========== |
|---|
| | 495 | |
|---|
| | 496 | The tutorial ends here for the time being. But check back within 48 hours for |
|---|
| | 497 | the next installments: |
|---|
| | 498 | |
|---|
| | 499 | * Writing public-facing apps |
|---|
| | 500 | * Using the cache framework |
|---|
| | 501 | * Using the RSS framework |
|---|
| | 502 | * Using the comments framework |
|---|