简体   繁体   English

访问django管理模板中的对象

[英]Accessing the object in a django admin template

I'm overriding the change_form.html template and want to display links to other related objects. 我正在覆盖change_form.html模板,并希望显示指向其他相关对象的链接。

When overriding an admin template, is there a way to access the object that is beeing edited in the template? 覆盖管理模板时,有没有办法访问模板中编辑的对象? Or perhaps pass that object to the template when registering it to the admin in some way? 或者以某种方式将该对象注册到管理员时将该对象传递给模板?

A quick look at django.contib.admin.options' change_view method shows the original object is included as a context variable called original . 快速浏览一下django.contib.admin.options的change_view方法,可以看到原始对象被包含为名为original的上下文变量。 So if you're simply overriding change_form.html itself you can get to the object being edited via {{ original }} . 因此,如果您只是覆盖change_form.html本身,则可以通过{{ original }}正在编辑的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM