0

I have a Python flask application which takes input id's and dynamically generates data into a html file. Below is my app.py file.

@app.route('/execute', methods=['GET', 'POST'])
def execute():
    if request.method == 'POST':
        id = request.form['item_ids']
        list = [id]
        script_output = subprocess.Popen(["python", "Search_Script.py"] + list)
        # script_output = subprocess.call("python Search_Script.py "+id, shell=True)
        # render_template('running.html')
        script_output.communicate()
        #driver = webdriver.Chrome()
        #driver.get("home.html")
        #driver.execute_script("document.getElementById('Executed').style.display = '';")
        return render_template('execute.html')

@app.route('/output')
def output():
    return render_template('output.html')

output.html file has below code at the bottom.

<div class="container" style="text-align: center;">
        {% include 'itemSearchDetails.html' %}
</div>

itemSearchDetails.html is generated every time dynamically based on the input. I check for different inputs and it is generating perfectly. When I run it with some input(assume 2) values for the first time, it runs perfectly and shows the output correctly. But, when I run for different values(assume 4) for the next time, the file 'itemSearchDetails.html' is generated for those 4 values but the browser only shows output for the first 2 values. No matter how many times I run it, browser shows only output with the first run values.

So, every time only the first inputted values are shown no matter how many times I run. I am not sure if it is browser cache issue since I tried "disabling cache" in chrome. Still it didn't work. Please let me know if there is something I am missing.

venky4t
  • 51
  • 7

2 Answers2

0

Try solution from this answer:

Parameter TEMPLATES_AUTO_RELOAD

Whether to check for modifications of the template source and reload it automatically. By default the value is None which means that Flask checks original file only in debug mode.

Original documentation could be found here.

Ignacio Vergara Kausel
  • 5,521
  • 4
  • 31
  • 41
Timofey Chernousov
  • 1,284
  • 8
  • 12
  • Excellent. This worked. Flask now check and loads the template file every time. Thanks a lot for the help. – venky4t Oct 26 '17 at 16:03
0

Looks like Jinja is caching the included template.

If you don't need to interpret the HTML as a Jinja template, but instead just include its contents as-is, read the file first and pass the contents into the template:

with open('itemSearchDetails.html', 'r') as infp:
    data = infp.read()
return render_template('execute.html', data=data)

...

{{ data|safe }}

(If you do need to interpret the HTML page as Jinja (as include will), you can parse a Jinja Template out of data, then use the include tag with that dynamically compiled template.)

AKX
  • 152,115
  • 15
  • 115
  • 172