如何仅针对 1 个应用程序覆盖 django edit_inline/tabular.html?
如果我将 edit_inline/tabular.html
保存在我的整个模板目录中(例如 mysite/templates/admin/edit_inline/tabular.html
),我可以覆盖它,但是当我尝试使用其他管理模板保存它,例如 change_form.html
(在 mysite/myapp/templates/admin/myapp/mymodel/change_form.html
中,它不起作用。
I can override edit_inline/tabular.html
if I save it in my overall template directory (for example mysite/templates/admin/edit_inline/tabular.html
), but when I try to save it with other admin template, like change_form.html
(in mysite/myapp/templates/admin/myapp/mymodel/change_form.html
, it doesn't works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到这个线程有点旧,实际上对于内联模型,您需要在 admin.py 中显式设置新模板,如下所示:
检查此
http://blog.ruedamillion.com/2011/ 05/django-journal-override-a-django-admin-template-inline-or-otherwise/I come across this thread which is a bit old, in fact for the inline model you need to explicitly set your new template in your admin.py like below :
check this
http://blog.ruedaminute.com/2011/05/django-journal-override-a-django-admin-template-inline-or-otherwise/文档提示内联可以有一个
template
属性。尝试将其设置为admin/myapp/mymodel/edit_inline/tabular.html
并在myapp
的templates
目录中创建相应的模板文件。The documentation hints that inlines can have a
template
attribute. Try setting that toadmin/myapp/mymodel/edit_inline/tabular.html
and create the corresponding template file in thetemplates
directory ofmyapp
.表单如下:
templates/admin/app_name/override.html
对于您的change_form.html示例,它应该如下所示:
mysite/templates/admin/myapp/change_form.html
请参阅http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding -admin-templates 了解更多。
The form is like this:
templates/admin/app_name/override.html
For you change_form.html example, it should be like this:
mysite/templates/admin/myapp/change_form.html
See http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates for more.