-
[Django] 템플릿(html)에서 파이썬 enumerate 사용Memo/Python 2023. 1. 30. 20:45
Django 템플릿에서 파이썬 enumerate 기능을 사용하려면 다음과 같이 코드를 for문 내부에 작성한다.
{% for n in network %} {{ forloop.counter }} {% endfor %}
위 코드는 1부터 시작하는 코드이다.
만약 파이썬의 enumerate 처럼 0부터 시작하고 싶다면 아래처럼 'counter'뒤에 0만 붙여주면 된다.
{% for n in network %} {{ forloop.counter0 }} {% endfor %}
how to run this code in django template
this is my code : {% for i,j in enumerate(a) %} {{i}} ,{{j}} {% endfor%} but , it show a error , i think it cant run the enumerate method , so how to run the enumerate in django template ,
stackoverflow.com
'Memo > Python' 카테고리의 다른 글
[Python] 'utf-8' codec can't decode byte 0xbe 에러 해결 (0) 2023.02.17 [Python] 텔레그램 API로 메시지 전송 방법 (마크다운, 이모지, 버튼) (0) 2023.02.13 [Selenium] 요소 위치로 스크롤 이동하기 (0) 2023.01.25 [Selenium] 결과 값 텍스트가 빈칸(공백)으로 리턴될 때 (0) 2023.01.18 [Selenium] 코드 실행 후 브라우저가 자동으로 종료될 때 (0) 2023.01.17