Adding link to admin page

998 views
Skip to first unread message

Larry Martell

unread,
Mar 25, 2012, 5:29:40 PM3/25/12
to django...@googlegroups.com
I have a client that has an app built with django. On every page of
their app is a link to their admin site. They tell me the admin site
is generated entirely by django, and they've never customized it
before. On the very first line of the admin page it says:

Django administration Welcome, admin. Change password / Log out

They want me to add a link to that line, to the left of "Django
administration" that will take them back to the page they were on when
they clicked on the link to get them to the admin site.

So I have 2 issues here:

1) How do I override that line to add the link? It appears that page
is generated by contrib/admin/templates/admin/base.html, and I tried
to override it by following the directions at
https://docs.djangoproject.com/en/1.2/ref/contrib/admin/#overriding-admin-templates,
but whatever I do seems to have no effect.

2) How can I get the link of the page of the app they came from? It's
not simply just going back one page, as they could have navigated all
over the place of the admin site before clicking the "Back to app"
link.

Thanks!
-larry

larry....@gmail.com

unread,
Mar 26, 2012, 6:16:35 PM3/26/12
to Django users
On Mar 25, 3:29 pm, Larry Martell <larry.mart...@gmail.com> wrote:
> I have a client that has an app built with django. On every page of
> their app is a link to their admin site. They tell me the admin site
> is generated entirely by django, and they've never customized it
> before. On the very first line of the admin page it says:
>
> Django administration          Welcome, admin. Change password / Log out
>
> They want me to add a link to that line, to the left of "Django
> administration" that will take them back to the page they were on when
> they clicked on the link to get them to the admin site.
>
> So I have 2 issues here:
>
> 1) How do I override that line to add the link? It appears that page
> is generated by contrib/admin/templates/admin/base.html, and I tried
> to override it by following the directions athttps://docs.djangoproject.com/en/1.2/ref/contrib/admin/#overriding-a...,
> but whatever I do seems to have no effect.
>
> 2) How can I get the link of the page of the app they came from? It's
> not simply just going back one page, as they could have navigated all
> over the place of the admin site before clicking the "Back to app"
> link.
>
> Thanks!
> -larry

Is there anyone that can provide some assistance with overriding
base_site.html? I copied django/contrib/admin/templates/admin/
base_site.html to my projects's templates/admin dir, but changes to it
are not getting picked up. I also tried adding that to TEMPLATE_DIRS
(there was nothing in it before). In urlpatterns I have: (r'^admin/',
include(admin.site.urls)) - does that need to change?

Mike Dewhirst

unread,
Mar 26, 2012, 6:37:20 PM3/26/12
to django...@googlegroups.com

Check https://docs.djangoproject.com/en/1.4/ref/settings/#template-loaders

Basically, django uses the first template it finds so if it finds the
"real" one in site-packages first, it stops looking. Try reversing the
sequence of loaders in your settings.py

Mike


>

Larry Martell

unread,
Mar 26, 2012, 7:16:01 PM3/26/12
to django...@googlegroups.com

Thanks. Perhaps that's related to the problem. TEMPLATE_LOADERS has this:

TEMPLATE_LOADERS = (
'appmngr.load_app_template',
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
)

Where the first entry is a custom template loader that doesn't appear
to know how to load something from my apps templates/admin dir. Are
the other 2 entries 'standard' loaders that would look for my
base_site.html (since I put full path to it in TEMPLATE_DIRS)?

Mike Dewhirst

unread,
Mar 26, 2012, 9:25:51 PM3/26/12
to django...@googlegroups.com
Here is mine ...

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

... it looks like your settings.py is using the template API
load_template_source() for some reason. If you didn't do that yourself,
I'd suggest you experiment by putting my two Loaders ahead of your three
and see what happens.

Good luck

Mike

Larry Martell

unread,
Mar 26, 2012, 9:46:56 PM3/26/12
to django...@googlegroups.com

No, I didn't set any of this up. It's an existing app, and I'm new to
both the job and to django. There's only one other developer working
on the project, and he's part time and doesn't always respond to my
questions.

In any case, I tried that and it had no effect. Thanks for trying.

-larry

Mike Dewhirst

unread,
Mar 26, 2012, 11:19:48 PM3/26/12
to django...@googlegroups.com
Larry

Here is a working setup ...

From settings.py
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # #
# if templates are not found here look in app_name/templates
TEMPLATE_DIRS = (
os.path.join(SRC_ROOT, 'templates/').replace('\\','/'),
)

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
# filesystem ahead of app_directories looks in project before django
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)

TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.contrib.messages.context_processors.messages',
)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # #

... where SRC_ROOT is the directory containing settings.py.

So my templates directory seems much the same as yours like this ...

SRC_ROOT/templates/admin/base_site.html

... and inside base_site.html I have ...
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{% extends "admin/base.html" %}
{# admin/base.html is in
site-packages/django/contrib/admin/templates/admin #}
{% load i18n %}
{% block title %}{{ title }} | {% trans 'Ssds' %}{% endblock %}
{% block extrastyle %}{% endblock %}
{% block branding %}
<h1 id="site-name">{% trans '<a href="http://www.myproj.com.au">MyProj
Administration</a>' %}</h1>
{% endblock %}
{% block nav-global %}{% endblock %}
{% block extrahead %}{% endblock %}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

... and you can see where I tested a link inside {% block branding %}
and I can confirm it works.

Hth

Mike

Mike Dewhirst

unread,
Mar 27, 2012, 12:12:46 AM3/27/12
to django...@googlegroups.com
I should have mentioned that {% extends "admin/base.html" %} is actually
extending the django admin/base.html in site-packages because there is
no such file in my SRC_ROOT/templates/admin directory.

Mike

Larry Martell

unread,
Mar 27, 2012, 8:00:38 AM3/27/12
to django...@googlegroups.com

I found my problem - I was putting the full path to the dir with my
base_site.html in TEMPLATE_DIRS (e.g. SRC_ROOT/templates/admin/). When
I removed the last dir and changed it to SRC_ROOT/templates/ it then
picked up my file.

Thanks very much Mike, I really appreciate all your help.

-larry

> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

Reply all
Reply to author
Forward
0 new messages