gpt4 book ai didi

python - Django 1.5 扩展 admin/change_form.html 对象工具

转载 作者:行者123 更新时间:2023-11-28 20:47:43 27 4
gpt4 key购买 nike

我是 Django 的新手,但我真的很喜欢它。但有时我似乎会遇到一些我似乎没有把事情弄对的地方。所以,我请求一些帮助和指导。

我正在尝试为我的一个模型扩展对象工具,这样我就可以在历史记录旁边添加一个打印按钮。

我的模板如下:

project/app/templates/admin/

成功扩展了 base_site.html,没有任何问题。

project/app/templates/admin/base_site.html

但是,当我像这样添加 change_form.html 时:

project/app/templates/admin/change_form.html

具有以下内容:

{% extends 'admin/change_form.html' %}

{% block object-tools %}
<a href="one">One</a>
<a href="one">Two</a>
{% endblock %}

我遇到异常:调用 Python 对象时超出最大递归深度

这似乎是我遗漏了一些非常基本的东西。

我尝试过的事情:

  • {% block %} 的多种变体
  • 扩展 base_site、base 等......
  • 添加/model 作为路径的一部分 (project/app/templates/admin/model/change_form.html)

我很困惑,没有成功。

P.S.:我也在使用这里的 Bootstrap 主题 http://riccardo.forina.me/bootstrap-your-django-admin-in-3-minutes/但出于这个问题的目的,我目前没有使用它。

最佳答案

问题是 {% extend %} block 中的 admin/change_form.html 被解析为 project/app/templates/admin/change_form .html.

一个解决方案是创建一个以您的应用命名的 templates 子目录 - 可能是 project/templates/admin/app/change_form.html

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.

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs-replacing-an-admin-template

关于python - Django 1.5 扩展 admin/change_form.html 对象工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18196506/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com