pythonjinja2

TemplateSyntaxError jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'result1'


I am trying to implement an application for comparison. There is a method as you can see below in the method. get_site_analysis

@app.route('/comparison/<site_id1>/<site_id2>', methods=['GET'])
def comparison(site_id1, site_id2):
    arable = ArableData()
    site1_result, site1_images, site1_site_id = get_site_analysis(arable, site_id1)
    site2_result, site2_images, site2_site_id = get_site_analysis(arable, site_id2)

    return render_template('comparison.html', data=[[site1_result, site1_images, site1_site_id], [site2_result, site2_images, site2_site_id]])

I am passing data to template data=[[site1_result, site1_images, site1_site_id], [site2_result, site2_images, site2_site_id]]).

Trying to access it as below gives me the error in subjext.

TemplateSyntaxError jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'result1'

The way I am trying to access is as below,

        {%
                result1 = data[0][0]
                image_list1 = data[0][1]
                site1_id = data[0][2]
                result2 = data[0][0]
                image_list2 = data[0][1]
                site2_id = data[0][2]
        %}

What am I doing wrong here? Please help...


Solution

  • What am I doing wrong here?

    You are trying to set multiple variables in one block and also without set keyword. The syntax is just invalid, there is nothing specific. You can learn how to set a variable for example from Set variable in jinja one assignment at a time. Check also jinja2 template designer documentation.