Opened 15 years ago

Closed 15 years ago

Last modified 10 years ago

#11115 closed Uncategorized (invalid)

overriding change_list.html causes 'maximum recursion depth exceeded' exceptin

Reported by: margieroginski@… Owned by: nobody
Component: Template system Version: 1.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am trying to override the admin sites' change_list.html, following
the example at:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-ad...

If I create templates/admin/myapp/change_list.html and just put this
in it (and nothing else):

{% extends "admin/change_list.html" %}

I get

Request Method:         GET
Request URL:    http://172.16.84.5:8042/admin/taskmanager/task/
Exception Type:         TemplateSyntaxError
Exception Value:

Caught an exception while rendering: maximum recursion depth exceeded
in cmp

Original Traceback (most recent call last):
  File "/tools/aticad/1.0/external/python-2.5.1/lib/python2.5/site-
packages/django/template/debug.py", line 71, in render_node
    result = node.render(context)
  File "/tools/aticad/1.0/external/python-2.5.1/lib/python2.5/site-
packages/django/template/loader_tags.py", line 71, in render
    compiled_parent = self.get_parent(context)
  File "/tools/aticad/1.0/external/python-2.5.1/lib/python2.5/site-
packages/django/template/loader_tags.py", line 64, in get_parent
    source, origin = find_template_source(parent, self.template_dirs)
  File "/tools/aticad/1.0/external/python-2.5.1/lib/python2.5/site-
packages/django/template/loader.py", line 70, in find_template_source
    source, display_name = loader(name, dirs)
  File "/tools/aticad/1.0/external/python-2.5.1/lib/python2.5/site-
packages/django/template/loaders/filesystem.py", line 31, in
load_template_source
    for filepath in get_template_sources(template_name,
template_dirs):
  File "/tools/aticad/1.0/external/python-2.5.1/lib/python2.5/site-
packages/django/template/loaders/filesystem.py", line 16, in
get_template_sources
    template_dirs = settings.TEMPLATE_DIRS
  File "/tools/aticad/1.0/external/python-2.5.1/lib/python2.5/site-
packages/django/utils/functional.py", line 270, in __getattr__
    if name == "__members__":
RuntimeError: maximum recursion depth exceeded in cmp

Exception Location:     /tools/aticad/1.0/external/python-2.5.1/lib/
python2.5/site-packages/django/template/debug.py in render_node, line
81

I'm using the beta:

django.VERSION

(1, 1, 0, 'beta', 1)

It has also been confirmed by another user on 1.0.2.

Change History (18)

comment:1 by Ramiro Morales, 15 years ago

What happens when you add some content to that template file? What are the values of your TEMPLATE_DIRS and TEMPLATE_LOADERS settings?. I'd suggest to post you case to the django-users mailing list.

comment:2 by Nick, 15 years ago

Component: UncategorizedTemplate system
Version: 1.1-beta-11.0

I am the other user who confirmed this on 1.0.2 Final.

Here is my change_list.html: http://dpaste.com/hold/43977/
Here is the error I get: http://dpaste.com/hold/43978/ (I omitted the repeating recursion errors and left you with a single instance of them)

Let me know if any more information is useful.

comment:3 by Nick, 15 years ago

Version: 1.01.1-beta-1

comment:4 by Nick, 15 years ago

And here are my TEMPLATE_LOADERS and TEMPLATE_DIRS:

TEMPLATE_LOADERS = (

'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
'django.template.loaders.eggs.load_template_source',

)

ipt = os.path.abspath(os.path.join(os.path.dirname(file), 'iptool'))
ipt_templates = os.path.join(ipt, "templates")
TEMPLATE_DIRS = (

ipt_templates,

)

comment:5 by Ramiro Morales, 15 years ago

See also #2414

comment:6 by Nick, 15 years ago

Sorry about the poor formatting in my previous comment.

This template was in the directory: iptools/templates/admin/.

I have changed the "{% extends "admin/change_list.html" %}" to "{% extends "/usr/local/lib/python2.6/site-packages/django/contrib/admin/templates/admin/change_list.html" %}" and everything works as expected.

Is this the correct solution or simply a convenient coincidence?

comment:7 by anonymous, 15 years ago

I did post this on the django users group on 5/7 at http://groups.google.com/group/django-users/browse_frm/thread/a965fa6cca5a563f#. The only response I got was from Nick, saying that he also sees the problem on 1.0.2.

I realize that I did have a problem in my initial bug post. In the stack trace that I posted, I was incorrectly using django 1.0.2 library files, rather than the beta 1.1 library files (ie, somehow had a weird mix of 1.1beta and 1.0.2 due to an incorrect installation of my 1.1 library). However, I still get the problem with a "good" beta 1.1, but a slightly different stack trace. I have put the details of my settings plus the stack trace at http://dpaste.com/hold/44060 and at the end of this message as well.

If I add content to the template, it makes no difference. Here is the contents of my change_list.html in my current test:

Here is the contents of change_list.html:
{% extends "admin/change_list.html" %}

{% block title %}HELLO{% endblock %}

Here are the value of my TEMPLATE_LOADERS and TEMPLATE_DIRS:

TEMPLATE_DIRS
('/home/mlevine/django/playproject/../playproject/templates', 'apps/diamandas/myghtyboard/templates', 'apps/diamandas/userpanel/templates', 'apps/diamandas/pages/templates')
TEMPLATE_LOADERS
('django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source')

Here is my os info:
lslogin3 site-packages/django/contrib/admin % uname -a
Linux lslogin3 2.4.21-37.ELsmp #1 SMP Wed Sep 7 13:32:18 EDT 2005 x86_64 x86_64 x86_64 GNU/Linux

Here is the environment and stack trace (can also be found at http://dpaste.com/hold/44060):

Environment:

Request Method: GET
Request URL: http://172.16.84.5:8050/admin/taskmanager/task/
Django Version: 1.1 beta 1
Python Version: 2.5.1
Installed Applications:
['django.contrib.auth',

'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.humanize',
'bookpub',
'membership',
'django_extensions',
'tagging',
'tagautocomplete',
'fkautocomplete',
'taskmanager',
'django.contrib.admin',
'django_evolution']

Installed Middleware:
('django.middleware.common.CommonMiddleware',

'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')

Template error:
In template /home/mlevine/django/playproject/apps/taskmanager/templates/admin/change_list.html, error at line 1

Caught an exception while rendering: maximum recursion depth exceeded
1 : {% extends "admin/change_list.html" %}

2 :

3 : {% block title %}HELLO{% endblock %}

4 :

5 :


Original Traceback (most recent call last):

File "/home/mlevine/django/django_libs/Django-1.1-beta-1/lib/python2.5/site-packages/django/template/debug.py", line 71, in render_node

result = node.render(context)

File "/home/mlevine/django/django_libs/Django-1.1-beta-1/lib/python2.5/site-packages/django/template/loader_tags.py", line 95, in render

parent_block.add_parent(parent_block.nodelist)

File "/home/mlevine/django/django_libs/Django-1.1-beta-1/lib/python2.5/site-packages/django/template/loader_tags.py", line 35, in add_parent

self.parent.add_parent(nodelist)

File "/home/mlevine/django/django_libs/Django-1.1-beta-1/lib/python2.5/site-packages/django/template/loader_tags.py", line 35, in add_parent

self.parent.add_parent(nodelist)

File "/home/mlevine/django/django_libs/Django-1.1-beta-1/lib/python2.5/site-packages/django/template/loader_tags.py", line 35, in add_parent

self.parent.add_parent(nodelist)

File "/home/mlevine/django/django_libs/Django-1.1-beta-1/lib/python2.5/site-packages/django/template/loader_tags.py", line 35, in add_parent

self.parent.add_parent(nodelist)

... lots more of the same ...
RuntimeError: maximum recursion depth exceeded

comment:8 by anonymous, 15 years ago

Thanks for suggesting using the absolute path to the admin change_list.html, Nick. I confirm that also works for me. I think there is a bug here, but at least this is a work around.

comment:9 by bohyn, 15 years ago

I have the same problem, when I use custom model methods for displaying values in admin change list interface. These methods are using a queryset, which is generated by custom Manager. This manager adds a 'select_related' clause to queryset. When I remove 'select_related' from its get_query_set() method, everything seems to be OK. I have tried SVN revisions 10863, 10844 and 10680.

comment:10 by Chris Beaven, 15 years ago

Resolution: invalid
Status: newclosed

A template can't extend itself (which is what you're trying to do). The fact it raises a python recursion error is wrong, but that's #2414

comment:11 by broderboy, 14 years ago

Version: 1.1-beta-11.1

I don't think the workaround works anymore

{% extends "/var/lib/python-support/python2.6/django/contrib/admin/templates/admin/change_list.html" %}

results in

Template u'/var/lib/python-support/python2.6/django/contrib/admin/templates/admin/change_list.html' cannot be extended, because it doesn't exist

but it does exist.

comment:12 by benjaoming, 14 years ago

Had the same issue... but if we read the documentation it says:

In order to override one or more of them, first create an admin directory in your project's templates directory. This can be any of the directories you specified in TEMPLATE_DIRS.

Within this admin directory, create sub-directories named after your app. Within these app subdirectories create sub-directories named after your models.

..and that solves it.

in reply to:  12 comment:13 by kevin@…, 13 years ago

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

Replying to benjaoming:

Had the same issue... but if we read the documentation it says:

In order to override one or more of them, first create an admin directory in your project's templates directory. This can be any of the directories you specified in TEMPLATE_DIRS.

Within this admin directory, create sub-directories named after your app. Within these app subdirectories create sub-directories named after your models.

..and that solves it.

The annoying part about that is that we can't have a site-wide admin override of change_list.html.

comment:14 by benjaoming, 13 years ago

You can! Put change_list.html in your local templates/admin and *don't* let it inherit from admin/change_list - instead just copy the whole file.

comment:15 by Mikhail Korobov, 13 years ago

See also: #15053, #8158

in reply to:  14 comment:16 by kevin@…, 13 years ago

Replying to benjaoming:

You can! Put change_list.html in your local templates/admin and *don't* let it inherit from admin/change_list - instead just copy the whole file.

How about overriding just one block of change_list.html? Copying the file doesn't seem to be the Django Way.

comment:17 by benjaoming, 13 years ago

No, but that's a workaround :) ...similarly you can make a symlink, call it something else and inherit from that.

comment:18 by anonymous, 10 years ago

A better way that avoids copying, symlinks or using the full path, is to use '..' to go up a directory or to and then back into a set of folders specific to the django admin templates.

See here for an example
http://stackoverflow.com/a/23696160/1280629

Note: See TracTickets for help on using tickets.
Back to Top