Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom django admin templates not working

I've been trying to get custom templates for the admin page for Django working but have been unsuccessful. I've read the django documentation and several blogs which explain it as being such an easy step, which I assumed it was.

As of right now the admin page works but my own rewrite of the CSS or templates is not working. My setup is as follows

/project_folder/
      manage.py
      settings.py
      urls.py
      __init__.py
      /app/
          views.py
          models.py
          __init__.py
          /templates/
                /admin/
                    base_site.html

In the urls.py I have

(r'^admin/', include(admin.site.urls)),

Which works since I cannot login etc. So I am assuming the /admin/base_site.html would overwrite the default one but it isn't doing a thing.

Anyone know what is going on here ? I followed it from the Django tutorials/guides and went onto some blogs to see if they had answers but they all said the same thing.

Edit 1: I do have my templates directory setup correctly.

TEMPLATE_DIRS = (
    os.path.join(PROJECT_PATH, 'templates/'),
)

This works correctly as I have the rest of my site working with a media directory for CSS etc. The only thing not seeming to 'accept' the templates is the admin section.

like image 293
Yonathan Avatar asked Aug 03 '12 10:08

Yonathan


2 Answers

Alright I fixed it, this was a stupid mistake but I was already playing with this for the past 2 hours. I had to declare my app before django.contrib.admin. It wouldn't accept it otherwise.

like image 158
Yonathan Avatar answered Oct 16 '22 10:10

Yonathan


One more mistake that one should resist making on this exercise. The exercise says to change this...

<h1 id="site-name"><a href="{% url 'admin:index' %}"> {{ site_header|default:_('Django administration') }} </a></h1>

to this...

<h1 id="site-name"><a href="{% url 'admin:index' %}">Polls Administration</a></h1>

There is a temptation to only change the string constant, but that is incorrect. I.e. do NOT do this, it will not alter the heading:

<h1 id="site-name"><a href="{% url 'admin:index' %}"> {{ site_header|default:_('Polls Administration') }} </a></h1>

That was the mistake I made, and I had to go through the exercise meticulously to fix it.

like image 41
M. K. Hunter Avatar answered Oct 16 '22 11:10

M. K. Hunter