What is the best way to dynamically build and insert templatetags from some data in settings.py
# .... in settings.py
DYN_TAGS = [
{
'name': 'foo',
'data': {
'code': 200,
'says': 'Foo here',
}
},
{
'name': 'bar',
'data': {
'code': 401,
'says': 'Bar here',
}
}
]
# ... in: foobar_app/__init__.py
from django.conf import settings
for tag in settings.DYN_TAGS:
# register tags
####### The above should be equal to #########
# if we had an app called foobar_app and it had a templatetags directory
# .... in: foobar_app/templatetags/foo.py
@register.assignment_tag(takes_context=True)
def foo(context):
return {'code': 200, 'says': 'Foo here'}
# .... in: foobar_app/templatetags/bar.py
@register.assignment_tag(takes_context=True)
def bar(context):
return {'code': 401, 'says': 'Bar here'}
Please note that the data is made up to help with the question.
Django 1.8+ answers would be great.
Thanks,
Val