djangochange_form.html
我想将参数{{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)
I'd like to pass an argument {{x}}
to my custom file change_form.html, which is located in /home/django/project/app/template/admin/change_form.html
. I found this code but it doesn't work:
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我实际上可以回答这个问题(对于通过谷歌找到这个问题的其他人)。
Django 1.4 实际上改变了change_view 的定义方式,并且您可能在互联网上找到的一些文档或片段尚未更新。
https://docs.djangoproject。 com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.change_view
换句话说,这应该有效:
I think I can actually answer this question (for anyone else that find this question through google).
Django 1.4 actually changed the way change_view is defined and some documentation or snippets you might find on the internet have not yet been updated.
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.change_view
In other words, this should work: