Skip to content

Instantly share code, notes, and snippets.

@DiegoYungh
Created April 3, 2014 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DiegoYungh/9955467 to your computer and use it in GitHub Desktop.
Save DiegoYungh/9955467 to your computer and use it in GitHub Desktop.
@register.assignment_tag
def cache_obj(obj):
"""Cache given obj"""
if not obj:
return ""
return obj
@register.assignment_tag
def get_value_from_dict(obj, key, *args, **kwargs):
"""Get value from target object/dict"""
try:
return obj[key]
except:
try:
return getattr(obj, key)(*args, **kwargs)
except:
pass
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment