Loading docs/ref/templates/builtins.txt +15 −6 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 somevar is not True %} This appears if somevar is not True, or if somevar is not found in the context. {% endif %} {% if value is not None %} This will output if and only if value is not None. {% if somevar is not None %} This appears if and only if somevar is not None. {% endif %} Filters Loading tests/template_tests/syntax_tests/test_if.py +20 −0 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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
docs/ref/templates/builtins.txt +15 −6 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 somevar is not True %} This appears if somevar is not True, or if somevar is not found in the context. {% endif %} {% if value is not None %} This will output if and only if value is not None. {% if somevar is not None %} This appears if and only if somevar is not None. {% endif %} Filters Loading
tests/template_tests/syntax_tests/test_if.py +20 −0 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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')