Fixed AttributeError from items filter when value is None (#5981)

This commit is contained in:
Craig de Stigter 2018-05-11 18:50:08 +12:00 committed by Carlton Gibson
parent c17b4ad0d0
commit 9629886915
2 changed files with 11 additions and 0 deletions

View File

@ -240,6 +240,10 @@ def items(value):
lookup. See issue #4931 lookup. See issue #4931
Also see: https://stackoverflow.com/questions/15416662/django-template-loop-over-dictionary-items-with-items-as-key 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() return value.items()

7
tests/test_templates.py Normal file
View File

@ -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')