I want to insert follium map into the jinja template.
run.py
from flask import Flask, render_template
app = Flask(__name__)
@app.rou
A different solution using iframe and render_template
Plus python flask code
# a hack going on here as web servers are caching folium generated template
# randomly move to a new name and then use render_template
@app.route('/get_map')
def get_map():
r = int(random.triangular(0,100))
t = "templates/map_{i}.html"
for i in range(0,100):
f = t.format(i=i)
if os.path.exists(f):
os.remove(f)
f = t.format(i=r)
shutil.copy("templates/map.html", f)
r = make_response(render_template(os.path.split(f)[1]))
r.cache_control.max_age = 0
r.cache_control.no_cache = True
r.cache_control.no_store = True
r.cache_control.must_revalidate = True
r.cache_control.proxy_revalidate = True
return r
Without the copy to a random filename before rendering httpd (on AWS beanstalk) / flask debug environment was not picking up new instance of folium html template. cache_control is not needed but was part of what I trialed to come to a solution. Clearly this solution is not thread safe