Yosi
Yosi

Reputation: 2966

Django Admin Templating

I am learning django and building my own project.
I want to change the admin section to my own interface, I have added sub-directory to the templates names "admin".And started change the base.html

The problems are-

  • I want to add my own css file, how I can do it?My css file is located on my MEDIA_ROOT directory.How I can do that?
  • I saw a lot of template tags,Where I can see which template tags are available to me on the admin section?
  • There is a clean admin template like Starkers for Wordpress
  • Yosy

    Upvotes: 0

    Views: 434

    Answers (2)

    OldTinfoil
    OldTinfoil

    Reputation: 1215

    For the Google stumbers out there:

    1. This is a much better way of overriding things in the admin template. Probably the most DRY method I've come across in my years of Django-ing.

      You should note that static files (like your css) should not be stored in the media folder. You should put them in the static folder. You don't want to be storing any user uploaded content in the same directory as your static files.
    2. Quoted from @cji 's response : "You can use all tags everywhere, if you {%load%}ed them before. There are admin specific tags, which could be found in Django source here - unfortunately I'm not aware of any docs about them, so seems like you have to read the source.
    3. I haven't stumbled across any in my travels. But unfortunately the images are broken for me on your site, so I can't be certain...

    Upvotes: 1

    cji
    cji

    Reputation: 6705

    1) If "django.core.context_processors.media" is included in TEMPLATE_CONTEXT_PROCESSORS (which is by default) in your settings.py, you can add <link> to {{ MEDIA_URL }}/your_stylesheet.css in templates/admin/base.html, like so (I'm using Django 1.2 admin templates):

    ...
    <link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% load adminmedia %}{% admin_media_prefix %}css/base.css{% endblock %}" />
    <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}/your_stylesheet.css" />
    ...
    

    2) You can use all tags everywhere, if you {%load%}ed them before. There are admin specific tags, which could be found in Django source here - unfortunately I'm not aware of any docs about them, so seems like you have to read the source.

    3) I haven't heard about such thing for Django admin, there is however project named Grappelli that improves Django admin looks and functionality, providing slightly friendlier templates as side effect.

    Upvotes: 1

    Related Questions