From 3313dab485979df7cc9f8fdf95e2a9a977dcdcf0 Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 29 Jun 2017 13:05:06 +0530 Subject: [PATCH] Added get_value_from_dict filter to obtain values from a dict in templates --- datacenterlight/templatetags/custom_tags.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/datacenterlight/templatetags/custom_tags.py b/datacenterlight/templatetags/custom_tags.py index 915e68fe..e7b15b5b 100644 --- a/datacenterlight/templatetags/custom_tags.py +++ b/datacenterlight/templatetags/custom_tags.py @@ -21,4 +21,14 @@ def change_lang(context, lang=None, *args, **kwargs): activate(cur_language) - return "%s" % url \ No newline at end of file + return "%s" % url + +@register.filter('get_value_from_dict') +def get_value_from_dict(dict_data, key): + """ + usage example {{ your_dict|get_value_from_dict:your_key }} + """ + if key: + return dict_data.get(key) + else : + return None