访问django管理模板中的对象

时间:2023-01-10 20:21:38

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?

当重写管理模板时,是否有方法访问在模板中被being编辑的对象?或者在以某种方式将该对象注册到管理员时将其传递给模板?

2 个解决方案

#1


53  

A quick look at django.contib.admin.options' change_view method shows the original object is included as a context variable called original. So if you're simply overriding change_form.html itself you can get to the object being edited via {{ original }}.

快速浏览一下django.contib.admin。选项的change_view方法显示原始对象被包含为一个称为原始的上下文变量。如果你只是重写change_form。html本身,您可以通过{{{{原始}}获取被编辑的对象。

#2


4  

yes, also you can see the complete context with django-debug-toolbar:

是的,你也可以看到完整的上下文与django调试工具栏:

http://screencast.com/t/c9dFHe7f

http://screencast.com/t/c9dFHe7f

#1


53  

A quick look at django.contib.admin.options' change_view method shows the original object is included as a context variable called original. So if you're simply overriding change_form.html itself you can get to the object being edited via {{ original }}.

快速浏览一下django.contib.admin。选项的change_view方法显示原始对象被包含为一个称为原始的上下文变量。如果你只是重写change_form。html本身,您可以通过{{{{原始}}获取被编辑的对象。

#2


4  

yes, also you can see the complete context with django-debug-toolbar:

是的,你也可以看到完整的上下文与django调试工具栏:

http://screencast.com/t/c9dFHe7f

http://screencast.com/t/c9dFHe7f