Q:

django template language for loops

so i have an html code that is using template variables.  For some reason it looks like after i iterate through a template variable, the list is empty?  Is it that the pointer need to be reset to the index 0 of the template variable?  thanks!  The second select has nothing to iterate over and has no option values.  Years is an array that  is like such [2015,2016,2017,2018]
<select data-placeholder="Choose Year 1..." id="yr1">
   {% for year in years %}
   <option value="{{year}}">{{year}}</option>
   {% endfor %}
</select>
<h4 style="margin-bottom: 0px; margin-right: 20px; margin-left: 20px">to</h4>
<select data-placeholder="Choose Year 2..." id="yr2">
   {% for year in years %}
   <option value="{{year}}">{{year}}</option>
   {% endfor %}
</select>

Here is the view
def organization_reports(request):
 now = datetime.datetime.now()
 years = reversed(["{0}".format(year) for year in range(now.year-7,now.year)])
 my_dict = {"years" : years}
 return render(request, 'organization_reports/organization.html', my_dict)

A:

reversed(..) does not construct a collection of elements: it is an iterator, so that means that it iterates over something (well it yields elements), and if it is exhausted, there is no (direct) way to repeat the enumeration. 
You thus need to materialize the iterator in some sort of collection, for example a list, or a tuple, for example:
def organization_reports(request):
    now = datetime.datetime.now()
    years = list(reversed(["{0}".format(year) for year in range(now.year-7,now.year)]))
    my_dict = {"years" : years}
    return render(request, 'organization_reports/organization.html', my_dict)
Or we can construct the list by reversing the range(..) object itself, that needs to be enumerated only once:
def organization_reports(request):
    now = datetime.datetime.now()
    years = ["{0}".format(year) for year in reversed(range(now.year-7,now.year))]
    my_dict = {"years" : years}
    return render(request, 'organization_reports/organization.html', my_dict)
or we can even encode the reversal in the range(..) object itself:
def organization_reports(request):
    now = datetime.datetime.now()
    years = ["{0}".format(year) for year in range(now.year-1,now.year-8, -1)]
    my_dict = {"years" : years}
    return render(request, 'organization_reports/organization.html', my_dict)
Regardless how we construct it, the result is that years is now a collection, not an iterator.  One can (normally) enumerate a collection an arbitrary number of times (and this definitely holds for lists and tuples).