-1

I'm working on getting a map to render in Flask. I'm not getting any errors, but the map is not rendering.

# function in flask to build map

def get_map():
    folium_map = folium.Map(location=[41.88, -87.62],
                            zoom_start=13,
                            tiles="cartodbpositron",
                            width='75%',
                            height='75%')    
    return folium_map

....
# rendering template

        mapvar = get_map()

        return flask.render_template('predictor.html',
                                    map = mapvar, 
                                    most_likely_class_prob = predictions,
                                    form = form)

And this is how I display it in my html file

<p> Map: {{map}} </p> 
<p> Probability: {{most_likely_class_prob}}

I'd appreciate any suggestions! I'm working on building this out further. Thanks you!

KMB
  • 79
  • 1
  • 10

1 Answers1

0

That is not how folium works. Folium creates a html file which you could include in your template like this https://medium.com/@drevets/how-to-display-html-folium-maps-using-jinja2-templating-with-flask-1d9ffb85dfc3

Or have a look at this solution https://python-visualization.github.io/folium/flask.html

Bear in mind folium will not offer a way to send data to your back-end. If that is what you need use leaflet without folium.

Edit: found this post on SO: Insert the folium maps into the jinja template

gittert
  • 1,238
  • 2
  • 7
  • 15