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?
How do you pass a Python variable to a template? And this is rather simple, because Django has built-in template modules that makes a transfer easy. Basically you just take the variable from views.py and enclose it within curly braces {{ }} in the template file.
In this article, we will discuss how to enhance Django-admin Interface. Let us create an app called state which has one model with the same name(state). When we register app to admin.py it shows like. Now lets' customize django admin according to available options.
One of the most powerful parts of Django is the automatic admin interface. It reads metadata from your models to provide a quick, model-centric interface where trusted users can manage content on your site. The admin's recommended use is limited to an organization's internal management tool.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With