Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Infinite recursion while extending the admin's app change_form template

I have the following template in template/admin/change_form.html:

{% extends "admin/change_form.html" %}
{% block extrahead %}
  {% include "dojango/base.html" %}
  {% block dojango_content %}
  {% endblock %}
{% endblock %}

However for some reason it throws a

TemplatesyntaxError: TemplateSyntaxError at /admin/cms/post/add/
Caught RuntimeError while rendering: maximum recursion depth exceeded while calling a Python object
like image 735
the_drow Avatar asked Feb 11 '11 12:02

the_drow


2 Answers

Also, you can point your AdminOptions class to another template using the change_form_template property.

Something like:

class MyOptions(AdminOptions):
    change_form_template = 'myapp/my_change_form.html'

And myapp/my_change_form.html:

{% extends "admin/change_form.html" %}
like image 194
ricobl Avatar answered Nov 15 '22 22:11

ricobl


I know it's late, but...

If extending - which is a far better option than duplicating - the key is to have it named anything except /admin/change_form.html.

(Although the OP referred to template/admin/change_form.html, this is simply because a path in his TEMPLATE_DIRS tuple ends in '/template' - mine generally end in '/templates' - but, these directories can be named anything and located anywhere.)

It will be used automatically on a per-app basis if named /admin/<MyAppName>/change_form.html

It will be used automatically on a per-model basis if named /admin/<MyAppName>/<MyModelName>/change_form.html

It can be named anything if specified explicitly in the ModelAdmin

class MyModelAdmin(admin.ModelAdmin):
    change_form_template = 'subdir/my_change_form.html'

Finally, if insistent on naming it /admin/change_form.html, you can - provided that the extends tag contains the full path to your django installation instead of a relative one.

like image 29
Frank Avatar answered Nov 15 '22 21:11

Frank