Refs #26479 -- Documented is/is not if tag operator behavior for nonexistent variables.
This commit is contained in:
parent
246020efc5
commit
dac075e910
|
@ -523,8 +523,12 @@ Not contained within. This is the negation of the ``in`` operator.
|
|||
|
||||
Object identity. Tests if two values are the same object. Example::
|
||||
|
||||
{% if value is None %}
|
||||
This will output if and only if value is None.
|
||||
{% if somevar is True %}
|
||||
This appears if and only if somevar is True.
|
||||
{% endif %}
|
||||
|
||||
{% if somevar is None %}
|
||||
This appears if somevar is None, or if somevar is not found in the context.
|
||||
{% endif %}
|
||||
|
||||
``is not`` operator
|
||||
|
@ -532,11 +536,16 @@ Object identity. Tests if two values are the same object. Example::
|
|||
|
||||
.. versionadded:: 1.10
|
||||
|
||||
Tests if two values are not the same object. This is the negation of
|
||||
the ``is`` operator. Example::
|
||||
Negated object identity. Tests if two values are not the same object. This is
|
||||
the negation of the ``is`` operator. Example::
|
||||
|
||||
{% if value is not None %}
|
||||
This will output if and only if value is not None.
|
||||
{% if somevar is not True %}
|
||||
This appears if somevar is not True, or if somevar is not found in the
|
||||
context.
|
||||
{% endif %}
|
||||
|
||||
{% if somevar is not None %}
|
||||
This appears if and only if somevar is not None.
|
||||
{% endif %}
|
||||
|
||||
Filters
|
||||
|
|
|
@ -564,6 +564,16 @@ class IfTagTests(SimpleTestCase):
|
|||
output = self.engine.render_to_string('template', {'foo': 1})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'template': '{% if foo is bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_is_variable_missing(self):
|
||||
output = self.engine.render_to_string('template', {'foo': 1})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'template': '{% if foo is bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_is_both_variables_missing(self):
|
||||
output = self.engine.render_to_string('template', {})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'template': '{% if foo is not None %}yes{% else %}no{% endif %}'})
|
||||
def test_if_is_not_match(self):
|
||||
# For this to act as a regression test, it's important not to use
|
||||
|
@ -575,3 +585,13 @@ class IfTagTests(SimpleTestCase):
|
|||
def test_if_is_not_no_match(self):
|
||||
output = self.engine.render_to_string('template', {'foo': None})
|
||||
self.assertEqual(output, 'no')
|
||||
|
||||
@setup({'template': '{% if foo is not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_is_not_variable_missing(self):
|
||||
output = self.engine.render_to_string('template', {'foo': False})
|
||||
self.assertEqual(output, 'yes')
|
||||
|
||||
@setup({'template': '{% if foo is not bar %}yes{% else %}no{% endif %}'})
|
||||
def test_if_is_not_both_variables_missing(self):
|
||||
output = self.engine.render_to_string('template', {})
|
||||
self.assertEqual(output, 'no')
|
||||
|
|
Loading…
Reference in New Issue