mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 11:04:02 +03:00
Fixed AttributeError from items filter when value is None (#5981)
This commit is contained in:
parent
c17b4ad0d0
commit
9629886915
|
@ -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()
|
||||
|
||||
|
||||
|
|
7
tests/test_templates.py
Normal file
7
tests/test_templates.py
Normal 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')
|
Loading…
Reference in New Issue
Block a user