Can I change the title of an admin page?

741 views
Skip to first unread message

Zeynel

unread,
Nov 16, 2009, 2:57:03 PM11/16/09
to Django users
I found that the base.html template takes the title in admin change
page from the title of the page:

line 64 in base.html:

{% block content_title %}{% if title %}<h1>{{ title }}</h1>{% endif %}
{% endblock %}

How can I change the title of the page? Does anyone know?

Also mentioned here:
http://code.djangoproject.com/changeset/1975

Zeynel

unread,
Nov 16, 2009, 3:35:13 PM11/16/09
to Django users
In case someone else has the same problem: I hard-coded the text I
wanted in between h1 tags in template base.html.

{% block content_title %}{% if title %}<h1>Enter last name</h1>{%
endif %}{% endblock %}

but this defeats the purpose of templates. If you know how titles are
created in django, please let me know.

Zeynel

unread,
Nov 16, 2009, 8:31:24 PM11/16/09
to Django users
RIDER 2:

pictures of the title I want to change:

http://zeynel.posterous.com/django-template-problem

lzantal

unread,
Nov 16, 2009, 9:56:51 PM11/16/09
to Django users
Hi,

In your templates/wkw1/lawyer dir extend change_list.html and override
the title::
{% extends "admin/change_list.html" %}
{% block content_title %}<h1>Your Title Here</h1>{% endblock %}

Hope it helps

lzantal
http://twitter.com/lzantal

Zeynel

unread,
Nov 17, 2009, 8:46:45 AM11/17/09
to Django users
I am sorry, I am new to django and I don't understand what I need to
do here. Do I create a new template file eg, mytemplate.html, in the
directory templates/wkw1/lawyer/mytemplates.html and copy and paste in
it

{% extends "admin/change_list.html" %}
{% block content_title %}<h1>Your Title Here</h1>{% endblock %}

My templates are in sw1/templates/admin

Thank you for your help.

On Nov 16, 9:56 pm, lzantal <lzan...@gmail.com> wrote:
> Hi,
>
> In your templates/wkw1/lawyer dir extend change_list.html and override
> the title::
> {% extends "admin/change_list.html" %}
> {% block content_title %}<h1>Your Title Here</h1>{% endblock %}
>
> Hope it helps
>
> lzantalhttp://twitter.com/lzantal

Karen Tracey

unread,
Nov 17, 2009, 8:57:48 AM11/17/09
to django...@googlegroups.com
On Tue, Nov 17, 2009 at 8:46 AM, Zeynel <azey...@gmail.com> wrote:
I am sorry, I am new to django and I don't understand what I need to
do here.

Zeynel

unread,
Nov 17, 2009, 9:46:04 AM11/17/09
to Django users
Ok, thanks. I read the "overriding admin templates" section. I want to
learn Django's template system and all these files are confusing to
me, but eventually I'll get it.

As instructed I created the directory system

~/webapps/django/sw1/templates/admin/wkw1/lawyer

Then, I copied change_list.html from

django/contrib/admin/templates/admin

and pasted it in

~/webapps/django/sw1/templates/admin/wkw1/lawyer

Then I copied

{% extends "admin/change_list.html" %}
{% block content_title %}<h1>Your Title Here</h1>{% endblock %}

and pasted on top of change_list.html.

I restarted the server. But I don't see the change. What am I doing
wrong?

Thanks again for your help.

On Nov 17, 8:57 am, Karen Tracey <kmtra...@gmail.com> wrote:
> On Tue, Nov 17, 2009 at 8:46 AM, Zeynel <azeyn...@gmail.com> wrote:
> > I am sorry, I am new to django and I don't understand what I need to
> > do here.
>
> You should read this section in the docs:
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-ad...
>
> Karen

lzantal

unread,
Nov 17, 2009, 12:45:54 PM11/17/09
to Django users
Don't copy the original change_list.html file over there.
Create a new empty change_list.html file and put the code in there I
posted previusly.
So your new file will have only 2 lines of code inside.
What it does is it extends the original template and thanks to django
blocks you overwrite the title section.

lzantal
http://twitter.com/lzantal

Ilya Polosuhin

unread,
Nov 17, 2009, 1:19:47 PM11/17/09
to django...@googlegroups.com
The folder for admin template is
path/to/your/project/templates/admin
So in your case you should put your own template to ~/webapps/django/sw1/templates/admin/


--

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=.



Zeynel

unread,
Nov 17, 2009, 1:48:19 PM11/17/09
to Django users
This worked, thanks.

But I had to change base.html as well (in ~/webapps/django/sw1/
templates/admin). Because previously I had hardcoded the {{ title }}
in line 65 in base.html

{% block content_title %}{% if title %}<h1>{{ title }}</h1>{% endif %}
{% endblock %}

I would like to ask, if you can help me understand how this line 65
gets the document title and if I can change the document title.
Because I prefer that {{ title }} remains there.

I actually want to make http://swimswith.com/admin/wkw1/ private
because I don't want the reviewers of the demo to see that page. I am
having problems with views as well so I'll ask that in another thread.

Thank you for the help

On Nov 17, 12:45 pm, lzantal <lzan...@gmail.com> wrote:
> Don't copy the original change_list.html file over there.
> Create a new empty change_list.html file and put the code in there I
> posted previusly.
> So your new file will have only 2 lines of code inside.
> What it does is it extends the original template and thanks to django
> blocks you overwrite the title section.
>
> lzantalhttp://twitter.com/lzantal

Karen Tracey

unread,
Nov 17, 2009, 7:02:43 PM11/17/09
to django...@googlegroups.com
On Tue, Nov 17, 2009 at 1:48 PM, Zeynel <azey...@gmail.com> wrote:
This worked, thanks.

But I had to change base.html as well (in ~/webapps/django/sw1/
templates/admin). Because previously I had hardcoded the {{ title }}
in line 65 in base.html

{% block content_title %}{% if title %}<h1>{{ title }}</h1>{% endif %}
{% endblock %}

I would like to ask, if you can help me understand how this line 65
gets the document title and if I can change the document title.
Because I prefer that {{ title }} remains there.


The value of title is set by the admin view code that renders admin templates. Note many different admin templates inherit from the base admin template, so there are many different places where the title value is set.  Search for 'title': on this page, for example:

http://code.djangoproject.com/browser/django/tags/releases/1.1.1/django/contrib/admin/sites.py

and you will see how it is set differently for a few different admin views (and there are others in other files).  Thus there is no knob or configuration option to change the value of title that is passed into the templates.  What there is is the ability to override templates, and specifically override the content of the content_title block.

Karen
Reply all
Reply to author
Forward
0 new messages