Django and Folium integration

前端 未结 3 1749
借酒劲吻你
借酒劲吻你 2020-12-18 05:28

Django newbie here: my aim is to integrate Folium to an html page. so what I have at the moment:

polls/views.py

def show_map(request         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-18 05:52

    You can get the html as a string by triggering the rendering on the (internal) parent of Map:

    m = folium.Map()
    html: str = m.get_root().render()
    

    Note that this returns a full html page, so you may need to put it in an iframe.

    Alternatively, you can render the head, body and script parts separately. That way you can put each part on your page where it belongs and you don't need an iframe:

    m = folium.Map()
    html_head: str = m.get_root().header.render()
    html_body: str = m.get_root().html.render()
    html_script: str = m.get_root().script.render()
    

提交回复
热议问题