'Python AttributeError: 'str' object has no attribute 'render'

I am getting the following error from the below code: AttributeError: 'str' object has no attribute 'render'.

I am trying to render the data from a specific row in an xlsx file with a Jinja2 template. The data is based on the first column being an 'action' column that the user fills in to indicate that is the row with the values they are interested in.

import jinja2
import openpyxl

inputFile = openpyxl.load_workbook('input-file.xlsx')
baseSheet = inputFile['base']
baseConfigTemplate = 'base-config.j2'
advaValues = {}
outputFile = ''

for row in range(2, baseSheet.max_row + 1):
    for column in range(1, baseSheet.max_column+1):
        advaValues[baseSheet.cell(row=1, column=column).value] = baseSheet.cell(row=row, column=column).value

    if advaValues['action'] is not None:
        filename = open(str(advaValues['hostname']) + ".txt", "a")
        filename.write(baseConfigTemplate.render(advaValues=advaValues))

Why is the render method flagging as an error?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source