Skip to content

Commit

Permalink
Fixed AttributeError from items filter when value is None (#5981)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigds authored and carltongibson committed May 11, 2018
1 parent c17b4ad commit 9629886
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rest_framework/templatetags/rest_framework.py
Expand Up @@ -240,6 +240,10 @@ def items(value):
lookup. See issue #4931
Also see: https://stackoverflow.com/questions/15416662/django-template-loop-over-dictionary-items-with-items-as-key
"""
if value is None:
# `{% for k, v in value.items %}` doesn't raise when value is None or
# not in the context, so neither should `{% for k, v in value|items %}`
return []
return value.items()


Expand Down
7 changes: 7 additions & 0 deletions tests/test_templates.py
@@ -0,0 +1,7 @@
from django.shortcuts import render


def test_base_template_with_no_context():
# base.html should be renderable with no context,
# so it can be easily extended.
render({}, 'rest_framework/base.html')

0 comments on commit 9629886

Please sign in to comment.