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

前端 未结 1 1996
迷失自我
迷失自我 2020-12-02 22:14

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条回答
  • 2020-12-02 23:02
    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

    0 讨论(0)
提交回复
热议问题