python - Django Template: How to modify the value in the for-loop tag? -


what want simple: want display html select tag includes option tags value 1971 ~ 2020.

the following code snippet:

year<select name="selected_year"> {% in "x"|rjust:"50" %}     <option value="{{ forloop.counter }}">{{ forloop.counter }}</option> {% endfor %} </select> 

the {{forloop.counter}} display 1 ~ 50.
question is: how display 1971 ~ 2020 instead?
suggestion?

btw, loop code referenced question: numeric loop in django templates

you could use |add filter modify each value:

<option value="{{ forloop.counter|add:1970 }}">{{ forloop.counter|add:1970 }}</option> 

but don't this. use range(1971, 2021) in view , pass template.


Comments