Django and Folium integration

前端 未结 3 1737
借酒劲吻你
借酒劲吻你 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:55

    You can try the below way. I also had faced the same issue and it worked great for me.

    views.py

    def show_map(request):  
        #creation of map comes here + business logic
        m = folium.Map([51.5, -0.25], zoom_start=10)
        test = folium.Html('Hello world', script=True)
        popup = folium.Popup(test, max_width=2650)
        folium.RegularPolygonMarker(location=[51.5, -0.25], popup=popup).add_to(m)
        m=m._repr_html_() #updated
        context = {'my_map': m}
    
        return render(request, 'polls/show_folium_map.html', context)
    

    show_folium_map.html

    {{ my_map|safe }}
    

提交回复
热议问题