Skip to content

Commit 6986a9e

Browse files
authored
added simple example using flask (#1140)
added simple example using flask
2 parents cc5e8d9 + a88d68f commit 6986a9e

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

docs/flask.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Using folium with flask
2+
=======================
3+
4+
A very common use case is to use folium with in a flask app.
5+
The trick is to return folium's HTML representation.
6+
Here is an example on how to d that:
7+
8+
9+
.. literalinclude:: ../examples/flask_example.py

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ Contents
3333

3434
installing
3535
quickstart.ipynb
36+
flask
3637
modules
3738
plugins

examples/flask_example.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
""" flask_example.py
2+
3+
Required packages:
4+
- flask
5+
- folium
6+
7+
Usage:
8+
9+
Start the flask server by running:
10+
11+
$ python flask_example.py
12+
13+
And then head to http://127.0.0.1:5000/ in your browser to see the map displayed
14+
15+
"""
16+
17+
from flask import Flask
18+
19+
import folium
20+
21+
app = Flask(__name__)
22+
23+
24+
@app.route('/')
25+
def index():
26+
start_coords = (46.9540700, 142.7360300)
27+
folium_map = folium.Map(location=start_coords, zoom_start=14)
28+
return folium_map._repr_html_()
29+
30+
31+
if __name__ == '__main__':
32+
app.run(debug=True)

0 commit comments

Comments
 (0)