How to create for and if loop for inputs in jinja flask

Solution
@app.route('/', methods=['GET', 'POST'])
def index():
    x = 4
    if request.method == 'POST':
        data = request.form.getlist('a', type=str)
        rslt = ' '.join(data)
    return render_template('index.html', **locals())


  
    
    
  
  
    
{% set ns = namespace(idx=0) %} {% for i in range(1,x) %} {% for j in range(i+1,x) %}
{% set ns.idx = ns.idx + 1 %} {% endfor %} {% endfor %}
{% if rslt %} {{ rslt }} {% endif %}
from itertools import combinations

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        data = request.form.getlist('a', type=str)
        rslt = ' '.join(data)
    x = 4
    pairs = combinations(range(1,x), 2)
    return render_template('index.html', **locals())


  
    
    
  
  
    
{% for i,j in pairs %}
{% endfor %}
{% if rslt %} {{ rslt }} {% endif %}