my mysite/templates/admin/base_site.html is ignored (tutorial unclear?)

252 views
Skip to first unread message

Andreas Ka

unread,
Nov 16, 2014, 1:15:59 PM11/16/14
to django...@googlegroups.com
so far all went fine - but now templates changes just don't work.



I think there must be a flaw in that tutorial, something missing,
or something different in django 1.7.1 ?


my versions:

python -c "import django; print(django.get_version())"
1.7.1

python --version
Python 2.7.3



SYMPTOM:

my changes in 
mysite/templates/admin/base_site.html   
are simply ignored.



These are my files:

mysite# tree
.
├── db.sqlite3
├── manage.py
├── mysite
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── polls
│   ├── admin.py
│   ├── __init__.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   └── __init__.py
│   ├── models.py
│   ├── tests.py
│   └── views.py
└── templates
    └── admin
        └── base_site.html



mysite/settings.py:

TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]


Whatever I do, the page
still keeps the old title 'Django administration'


I want to understand how templates work, because I need them for my real project.

Thanks a lot!


RLF_UNIQUE

unread,
Nov 16, 2014, 1:19:49 PM11/16/14
to django...@googlegroups.com
Obviously you've restarted the server and refreshed the page in such a way to ensure it's not a caching issue ?

Andreas Ka

unread,
Nov 16, 2014, 10:04:53 PM11/16/14
to django...@googlegroups.com
thanks for your answer.

yes, I just tried that. Same result.
By now, I have understood much more about the templates.
But still, for the admin pages
mysite/templates/admin/base_site.html   
doesn't work yet.



I have actually found more errors in the tutorial:


didn't work until I put a <body> tag into  polls/templates/polls/index.html



these tests all come up with one or the other assertion error





On Sun, Nov 16, 2014 at 7:19 PM, RLF_UNIQUE <rlfu...@gmail.com> wrote:
Obviously you've restarted the server and refreshed the page in such a way to ensure it's not a caching issue ?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2dfc3c89-cf1a-411f-ab0b-c15e7e09d501%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Artie

unread,
Nov 17, 2014, 8:11:26 AM11/17/14
to django...@googlegroups.com
Are you sure about correct path to your templates in views?

Show your view code

понедельник, 17 ноября 2014 г., 5:04:53 UTC+2 пользователь Andreas Ka написал:

Andreas Ka

unread,
Nov 17, 2014, 4:12:27 PM11/17/14
to django...@googlegroups.com

> Show your view code
The tutorial did not create any view.py for the admin pages




We copied from the Django source files these two into:
/mysite/templates/admin/base_site.html
and
/mysite/templates/admin/index.html



edited:


admin.py

from django.contrib import admin

# Register your models here.

from django.contrib import admin
from polls.models import Choice, Question


class ChoiceInline(admin.TabularInline):
    model = Choice
    extra = 3


class QuestionAdmin(admin.ModelAdmin):
    fieldsets = [
        (None,               {'fields': ['question_text']}),
        ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
    ]
    inlines = [ChoiceInline]
    list_display = ('question_text', 'pub_date', 'was_published_recently')
    list_filter = ['pub_date']
    search_fields = ['question_text']    

admin.site.register(Question, QuestionAdmin)


-------



On Mon, Nov 17, 2014 at 2:11 PM, Artie <giliar...@gmail.com> wrote:
Are you sure about correct path to your templates in views?

Show your view code

понедельник, 17 ноября 2014 г., 5:04:53 UTC+2 пользователь Andreas Ka написал:
thanks for your answer.

yes, I just tried that. Same result.
 
By now, I have understood much more about the templates.
 
But still, for the admin pages
mysite/templates/admin/base_site.html   
doesn't work yet.


...

Collin Anderson

unread,
Nov 20, 2014, 9:24:14 PM11/20/14
to django...@googlegroups.com
Hi,

Do other templates work in that folder?

Collin

Andreas Ka

unread,
Nov 21, 2014, 1:59:19 PM11/21/14
to django...@googlegroups.com
I don't know.
How to test that?



The things I have done were these:

mkdir templates
mkdir templates/admin
cp /usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/admin/base_site.html templates/admin/

ls -l templates/admin/base_site.html
-rw-r--r-- 1 user group 338 Nov 21 18:50 templates/admin/base_site.html
(and www-data is member of that group)

nano templates/admin/base_site.html   -> changed it to what I want to see
nano mysite/settings.py  -->   TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]

restarted the server.







--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

donarb

unread,
Nov 21, 2014, 5:08:45 PM11/21/14
to django...@googlegroups.com
Check your settings file, are there two TEMPLATE_DIRS variables defined? Possibly you created one in your edit, but Django already has an empty one defined. If your edit was placed before the one that is already defined, it would end up empty, hence no override. 

Andreas Ka

unread,
Nov 22, 2014, 8:05:30 PM11/22/14
to django...@googlegroups.com
Thanks for your help.

I really think there is something wrong with that part of the tutorial. A small thing, but wrong.


Check your settings file,
> are there two TEMPLATE_DIRS variables defined?

Nope. 


This is where I placed it:

...
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
...


just tried this:

import mysite.settings as settings
print settings.TEMPLATE_DIRS
['D:\\Programming\\eclipse\\mysite\\templates']

so no: not empty.


Why is my file templates/admin/base_site.html never called


Thanks.


Collin Anderson

unread,
Nov 25, 2014, 8:33:02 AM11/25/14
to django...@googlegroups.com
Hi,

Wow. Everything you've shown looks right.

Here's something to try: replace base_site.html with a completely empty file. That should cause the admin page to be completely blank.

If that works, could you post a snippet of where you're changing the template? Are you changing the <title> and expecting the <h1> to be different?

Collin

donarb

unread,
Nov 25, 2014, 9:51:27 AM11/25/14
to django...@googlegroups.com
Yea, can we see your base_site.html?

Marc Moncrief

unread,
Feb 12, 2015, 12:11:56 AM2/12/15
to django...@googlegroups.com, andre...@gmail.com
I've been going through the tutorial and had the same problem. The docs say
 "Create a templates directory in your project directory. "
I don't know if this will apply to you, but I thought that meant to put it in the poll directory. They mean to put it in the mysite directory. I made that change and my template changes started to be applied.

The information contained in this e-mail message and any accompanying files is or may be confidential. If you are not the intended recipient, any use, dissemination, reliance, forwarding, printing or copying of this e-mail or any attached files is unauthorised. This e-mail is subject to copyright. No part of it should be reproduced, adapted or communicated without the written consent of the copyright owner. If you have received this e-mail in error please advise the sender immediately by return e-mail or telephone and delete all copies. Fairfax Media does not guarantee the accuracy or completeness of any information contained in this e-mail or attached files. Internet communications are not secure, therefore Fairfax Media does not accept legal responsibility for the contents of this message or attached files.

Djarum Tujuhenam

unread,
Feb 16, 2015, 1:37:20 PM2/16/15
to django...@googlegroups.com, andre...@gmail.com
I am using Debian 7 and Python 2.7, Django version 1.7

Reading the Tutorial on the exactly same page : https://docs.djangoproject.com/en/1.7/intro/tutorial02/

The result is our admin template completely ignored.


Bryan Arguello

unread,
Mar 8, 2015, 3:09:19 PM3/8/15
to django...@googlegroups.com, andre...@gmail.com
Have you solved this problem, Andreas?  I am having the same issue and have done
everything that the tutorial described as well as everything that people on this thread
have suggested.

Collin Anderson

unread,
Mar 10, 2015, 1:14:27 PM3/10/15
to django...@googlegroups.com, andre...@gmail.com
Hi,

To be clear, you should have this setting:
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]

and in your mysite/templates/admin/base_site.html you should have something like:

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

Does that all look right?

Thanks,
Collin

fernando...@fdvsolutions.com

unread,
Mar 12, 2015, 12:00:11 PM3/12/15
to django...@googlegroups.com, andre...@gmail.com
Try this:


mysite# tree
.
├── db.sqlite3
├── manage.py
├── mysite
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── polls
     ├── admin.py
     ├── __init__.py
     ├── migrations
     │   ├── 0001_initial.py
     │   └── __init__.py
     ├── models.py
     ├── tests.py
     └── views.py
     └── templates
            └── admin
                    └── base_site.html




woodz

unread,
Apr 22, 2016, 7:52:30 AM4/22/16
to Django users, andre...@gmail.com
Aloha Andreas Ka,

have you been able to get this to work? I am currently going through the version 1.9 and facing the same issue. Is the suggestion of
Marc Moncrief a way to go? Did you go for your own solution and would you mind to share?
Thanks a lot
, woodz

Chris Bartos

unread,
Apr 23, 2016, 2:38:23 PM4/23/16
to Django users, andre...@gmail.com
I'm going to attach my 'mysite' project using Django 1.7 where customizing templates/admin/base_site.html actually works.
You can compare what you did wrong with what I did to get it to work.

Disclaimer: I actually did everything the tutorial said to do. So, I'm pretty sure the tutorial actually works.
mysite.zip

Luis Zárate

unread,
Apr 25, 2016, 6:34:06 PM4/25/16
to django...@googlegroups.com
Sory for not answer before, but I think I could help.

First you need to know how django find the templates, so take a look template loaders

https://docs.djangoproject.com/en/1.9/ref/templates/api/#django.template.loaders.filesystem.Loader

There are two default loaders (filesystem and app )

['django.template.loaders.filesystem.Loader',
 'django.template.loaders.app_directories.Loader']

so take a look https://docs.djangoproject.com/en/1.9/ref/settings/#template-loaders

So is important the app order.




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
"La utopía sirve para caminar" Fernando Birri


Amar Zamoum

unread,
Mar 12, 2023, 1:33:40 PM3/12/23
to Django users
I just had the same problem, and i realized that i had the templates file in the wrong "mysite" folder. It is easy to confuse the two, so for whoever has the same problem, just check where exactly you have put the "template/admin" folders, because in the tutorial it says to put inside the folder that contains the manage.py file.
Reply all
Reply to author
Forward
0 new messages