我想将一个参数传递{{x}}
给我的自定义文件 change_form.html,该文件位于/home/django/project/app/template/admin/change_form.html
. 我找到了这段代码,但它不起作用:
class MyModelAdmin(admin.ModelAdmin):
# A template for a very customized change view:
change_form_template = 'admin/change_form.html'
def get_osm_info(self):
z = Klass()
x = z.final_down()
return x
def change_view(self, request, object_id, extra_context=None):
my_context = { 'x': get_osm_info(),}
return super(MyModelAdmin, self).change_view(request, object_id,extra_context=my_context)