diff --git a/publik_django_templatetags/publik/templatetags/publik.py b/publik_django_templatetags/publik/templatetags/publik.py index 26932bc..07eaaf3 100644 --- a/publik_django_templatetags/publik/templatetags/publik.py +++ b/publik_django_templatetags/publik/templatetags/publik.py @@ -63,7 +63,7 @@ def split(string, separator=' '): def first(value): try: return defaultfilters.first(value) - except TypeError: + except (TypeError, KeyError): return '' @@ -71,7 +71,7 @@ def first(value): def last(value): try: return defaultfilters.last(value) - except TypeError: + except (TypeError, KeyError): return '' diff --git a/tests/test_publik.py b/tests/test_publik.py index 8904b16..c34a60e 100644 --- a/tests/test_publik.py +++ b/tests/test_publik.py @@ -78,6 +78,9 @@ def test_first(): context = Context({'foo': None}) assert t.render(context) == '' + context = Context({'foo': {}}) + assert t.render(context) == '' + def test_last(): t = Template('{{ foo|last }}') @@ -94,6 +97,9 @@ def test_last(): context = Context({'foo': None}) assert t.render(context) == '' + context = Context({'foo': {}}) + assert t.render(context) == '' + def test_decimal(): tmpl = Template('{{ plop|decimal }}')