mirror of
https://github.com/django/django.git
synced 2025-10-28 16:16:12 +00:00
Fixed #23913 -- Deprecated the = comparison in if template tag.
This commit is contained in:
@@ -999,7 +999,7 @@ def do_if(parser, token):
|
||||
``{% if 1>2 %}`` is not a valid if tag.
|
||||
|
||||
All supported operators are: ``or``, ``and``, ``in``, ``not in``
|
||||
``==`` (or ``=``), ``!=``, ``>``, ``>=``, ``<`` and ``<=``.
|
||||
``==``, ``!=``, ``>``, ``>=``, ``<`` and ``<=``.
|
||||
|
||||
Operator precedence follows Python.
|
||||
"""
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
"""
|
||||
Parser and utilities for the smart 'if' tag
|
||||
"""
|
||||
import warnings
|
||||
|
||||
from django.utils.deprecation import RemovedInDjango20Warning
|
||||
|
||||
|
||||
# Using a simple top down parser, as described here:
|
||||
@@ -99,6 +102,7 @@ OPERATORS = {
|
||||
'not': prefix(8, lambda context, x: not x.eval(context)),
|
||||
'in': infix(9, lambda context, x, y: x.eval(context) in y.eval(context)),
|
||||
'not in': infix(9, lambda context, x, y: x.eval(context) not in y.eval(context)),
|
||||
# This should be removed in Django 2.0:
|
||||
'=': infix(10, lambda context, x, y: x.eval(context) == y.eval(context)),
|
||||
'==': infix(10, lambda context, x, y: x.eval(context) == y.eval(context)),
|
||||
'!=': infix(10, lambda context, x, y: x.eval(context) != y.eval(context)),
|
||||
@@ -174,6 +178,11 @@ class IfParser(object):
|
||||
except (KeyError, TypeError):
|
||||
return self.create_var(token)
|
||||
else:
|
||||
if token == '=':
|
||||
warnings.warn(
|
||||
"Operator '=' is deprecated and will be removed in Django 2.0. Use '==' instead.",
|
||||
RemovedInDjango20Warning, stacklevel=2
|
||||
)
|
||||
return op()
|
||||
|
||||
def next_token(self):
|
||||
|
||||
Reference in New Issue
Block a user