Django how to pass custom variables to context to use in custom admin template?

这一生的挚爱 提交于 2019-12-28 02:49:13

问题


I am extending change_list.html and I need to output a variable defined in settings.py.

How do I pass that particular variable into the custom admin template context?


回答1:


class MyModelAdmin(admin.ModelAdmin):
    ...
    def changelist_view(self, request, extra_context=None):
        extra_context = extra_context or {}
        extra_context['some_var'] = 'This is what I want to show'
        return super(MyModelAdmin, self).changelist_view(request, extra_context=extra_context)

See: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.changelist_view



来源:https://stackoverflow.com/questions/9220042/django-how-to-pass-custom-variables-to-context-to-use-in-custom-admin-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!