扩展管理员的应用程序change_form模板时,Infinte递归 [英] Infinte recursion while extending the admin's app change_form template

查看:86
本文介绍了扩展管理员的应用程序change_form模板时,Infinte递归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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

任何人都可以告诉我我做错了什么?

Can anyone tell me what am I doing wrong?

推荐答案

我知道晚了,但... ...

I know it's late, but...

扩展 - 这是一个比复制更好的选择 - 关键是将其命名为 /admin/change_form.html

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

(虽然OP参考了 template / admin / change_form.html ,但这只是因为他的路径TEMPLATE_DIRS元组以'/ template'结尾 - 我的通常以'/ templates'结尾 - 但是这些目录可以命名为任何位置。)

(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.)

将被使用如果命名为 /admin/<MyAppName>/change_form.html

如果命名为 / admin /< MyAppName> /< MyModelName> /change_form.html

如果在ModelAdmin中明确指定,可以命名任何内容

It can be named anything if specified explicitly in the ModelAdmin

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

最后,如果坚持命名它 /admin/change_form.html ,您可以 - 如果扩展标记包含django安装程序的完整路径一个相对的tead。

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.

这篇关于扩展管理员的应用程序change_form模板时,Infinte递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆