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
dbfcedb4
Kaydet (Commit)
dbfcedb4
authored
Nis 06, 2017
tarafından
kapil garg
Kaydeden (comit)
Tim Graham
Nis 06, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28001 -- Updated comment and tested context popping in ForNode.render().
üst
351835f2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
5 deletions
+20
-5
defaulttags.py
django/template/defaulttags.py
+3
-5
test_for.py
tests/template_tests/syntax_tests/test_for.py
+17
-0
No files found.
django/template/defaulttags.py
Dosyayı görüntüle @
dbfcedb4
...
...
@@ -211,11 +211,9 @@ class ForNode(Node):
nodelist
.
append
(
node
.
render_annotated
(
context
))
if
pop_context
:
# The loop variables were pushed on to the context so pop them
# off again. This is necessary because the tag lets the length
# of loopvars differ to the length of each set of items and we
# don't want to leave any vars from the previous loop on the
# context.
# Pop the loop variables pushed on to the context to avoid
# the context ending up in an inconsistent state when other
# tags (e.g., include and with) push data to context.
context
.
pop
()
return
mark_safe
(
''
.
join
(
nodelist
))
...
...
tests/template_tests/syntax_tests/test_for.py
Dosyayı görüntüle @
dbfcedb4
...
...
@@ -180,3 +180,20 @@ class ForTagTests(SimpleTestCase):
def
test_for_tag_unpack14
(
self
):
with
self
.
assertRaisesMessage
(
ValueError
,
'Need 2 values to unpack in for loop; got 1.'
):
self
.
engine
.
render_to_string
(
'for-tag-unpack14'
,
{
'items'
:
(
1
,
2
)})
@setup
({
'main'
:
'{
%
with alpha=alpha.values
%
}{
%
include "base"
%
}{
%
endwith
%
}_'
'{
%
with alpha=alpha.extra
%
}{
%
include "base"
%
}{
%
endwith
%
}'
,
'base'
:
'{
%
for x, y in alpha
%
}{{ x }}:{{ y }},{
%
endfor
%
}'
})
def
test_for_tag_context
(
self
):
"""
ForNode.render() pops the values it pushes to the context (#28001).
"""
output
=
self
.
engine
.
render_to_string
(
'main'
,
{
'alpha'
:
{
'values'
:
[(
'two'
,
2
),
(
'four'
,
4
)],
'extra'
:
[(
'six'
,
6
),
(
'eight'
,
8
)],
},
})
self
.
assertEqual
(
output
,
'two:2,four:4,_six:6,eight:8,'
)
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