Reputation: 8227
Is there a way to access the ADMINS
variable of the settings
module from an any arbitrary template without adding manually adding it into the context before being rendered, similar to how request
is available in any template using RequestContext
if django.core.context_processors.request
is in TEMPLATE_CONTEXT_PROCESSORS
?
Upvotes: 1
Views: 1306
Reputation: 266
I'd use a template tag like discussed for this question: Can I access constants in settings.py from templates in Django?
Specifically I use the code from this answer: https://stackoverflow.com/a/6343321/2250326
With that you can get at the AMDINS in your templates like this:
{% value_from_settings "ADMINS" as admins %}
{% for admin in admins %}
Name: {{ admin.0 }}<br />
Email: {{ admin.1 }}
{% endfor %}
Upvotes: 2
Reputation: 122376
You can write your own context processor (which is a regular function that has request
as parameter):
from django.conf import settings
def admin_emails(request):
return { 'ADMINS': settings.ADMINS }
and add path.to.my.context_processor.admin_emails
to TEMPLATE_CONTEXT_PROCESSORS
.
Upvotes: 6