Using folium with flask¶
A very common use case is to use folium with in a flask app. The trick is to return folium’s HTML representation. Here is an example on how to d that:
""" flask_example.py
Required packages:
- flask
- folium
Usage:
Start the flask server by running:
$ python flask_example.py
And then head to http://127.0.0.1:5000/ in your browser to see the map displayed
"""
from flask import Flask
import folium
app = Flask(__name__)
@app.route('/')
def index():
start_coords = (46.9540700, 142.7360300)
folium_map = folium.Map(location=start_coords, zoom_start=14)
return folium_map._repr_html_()
if __name__ == '__main__':
app.run(debug=True)