Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
c00ae7f5
Kaydet (Commit)
c00ae7f5
authored
Ock 22, 2016
tarafından
Preston Timmons
Kaydeden (comit)
Tim Graham
Ock 22, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #26118 -- Added 'is' operator to if template tag.
üst
a08d2463
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
1 deletion
+25
-1
smartif.py
django/template/smartif.py
+1
-0
builtins.txt
docs/ref/templates/builtins.txt
+12
-1
1.10.txt
docs/releases/1.10.txt
+2
-0
test_if.py
tests/template_tests/syntax_tests/test_if.py
+10
-0
No files found.
django/template/smartif.py
Dosyayı görüntüle @
c00ae7f5
...
...
@@ -98,6 +98,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
)),
'is'
:
infix
(
10
,
lambda
context
,
x
,
y
:
x
.
eval
(
context
)
is
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
)),
'>'
:
infix
(
10
,
lambda
context
,
x
,
y
:
x
.
eval
(
context
)
>
y
.
eval
(
context
)),
...
...
docs/ref/templates/builtins.txt
Dosyayı görüntüle @
c00ae7f5
...
...
@@ -432,7 +432,7 @@ Use of actual parentheses in the :ttag:`if` tag is invalid syntax. If you need
them to indicate precedence, you should use nested :ttag:`if` tags.
:ttag:`if` tags may also use the operators ``==``, ``!=``, ``<``, ``>``,
``<=``, ``>=``
and ``in
`` which work as follows:
``<=``, ``>=``
, ``in``, and ``is
`` which work as follows:
``==`` operator
^^^^^^^^^^^^^^^
...
...
@@ -524,6 +524,17 @@ you should use::
{% if a > b and b > c %}
``is`` operator
^^^^^^^^^^^^^^^
.. versionadded:: 1.10
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.
{% endif %}
Filters
~~~~~~~
...
...
docs/releases/1.10.txt
Dosyayı görüntüle @
c00ae7f5
...
...
@@ -291,6 +291,8 @@ Templates
:class:`~django.template.backends.django.DjangoTemplates` backend and the
:class:`~django.template.Engine` class.
* Added the ``is`` comparison operator to the :ttag:`if` tag.
Tests
~~~~~
...
...
tests/template_tests/syntax_tests/test_if.py
Dosyayı görüntüle @
c00ae7f5
...
...
@@ -527,3 +527,13 @@ class IfTagTests(SimpleTestCase):
# A single equals sign is a syntax error.
with
self
.
assertRaises
(
TemplateSyntaxError
):
self
.
engine
.
render_to_string
(
'if-tag-single-eq'
,
{
'foo'
:
1
})
@setup
({
'template'
:
'{
%
if foo is True
%
}yes{
%
else
%
}no{
%
endif
%
}'
})
def
test_if_is_match
(
self
):
output
=
self
.
engine
.
render_to_string
(
'template'
,
{
'foo'
:
True
})
self
.
assertEqual
(
output
,
'yes'
)
@setup
({
'template'
:
'{
%
if foo is True
%
}yes{
%
else
%
}no{
%
endif
%
}'
})
def
test_if_is_no_match
(
self
):
output
=
self
.
engine
.
render_to_string
(
'template'
,
{
'foo'
:
1
})
self
.
assertEqual
(
output
,
'no'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment