I have an error in django template for loop

I have an error in django template for loop.    
My code: 
     <div class="form-group col-md-4 form-field">
                                        <label>Year</label>
                                        <select name="year" id="year" name="year">
                                            {% for y in range(1980, (datetime.datetime.now().year + 1)) %}
                                                <option value="{{ y }}">{{ y }}</option>
                                            {% endfor %}
                                        </select>
                                    </div>
    
    My error:
    'for' statements should use the format 'for x in y': for x in y range(1980, (datetime.datetime.now().year + 1))
    
    Please help me to resolve this issue.

Please help me to resolve this issue. Please help me to resolve this issue.

You cannot use standard Python logic in templates.

Read DOCS about that topic.

The easiest way seems to create custom template tag filter:

import datetime
from django import template

register = template.Library()

@register.filter
def get_year_range(starting_year):
    return range(int(starting_year), (datetime.datetime.now().year + 1))

And use it in template:

{% load custom_tags %}

...
{% for y in "1980"|get_year_range %}
    <option value="{{ y }}">{{ y }}</option>
{% endfor %}

MORE ABOUT TEMPLATE TAGS

I solve my issue using following code:
 import datetime

 today = datetime.date.today()
        year = today.year
        year_dropdown = []
        for y in range(year,1899,-1):
            year_dropdown.append(y)

Pass key in render

return render(request, "add-ad.html",
                      {'year_dropdown': year_dropdown })

My html form django template code:
  <div class="form-group col-md-4 form-field">
                                    <label>Year</label>
                                    <select name="year" id="year" name="year" class="form-control basic-select">
                                        <option value="">Choose...</option>
                                        {% for y in year_dropdown %}
                                      
                                        <option value="{{ y }}">{{ y }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                
Back to Top