Last active
October 27, 2022 13:41
-
-
Save wachunei/f7f1bb9bca0a74bb1053 to your computer and use it in GitHub Desktop.
Numeric for loop in Django Templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Iterate N times (replace N with a number --> | |
{% for i in "x"|ljust:"N" %} | |
<!-- Access numeric variable (0-based index) --> | |
{{ forloop.counter0 }} | |
<!-- Access numeric variable (1-based index) --> | |
{{ forloop.counter }} | |
{% endfor %} | |
<!-- For example, iterate from 0 to 3 --> | |
{% for i in "x"|ljust:"3" %} | |
<!-- Do stuff --> | |
{% endfor %} |
@bellydrum @kanik9 https://docs.djangoproject.com/en/3.1/ref/templates/builtins/#ljust
It is used only to make the string the size of the iteration.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is ljust ??