Creating marker on map using Folium results in blank HTML page

后端 未结 2 1357
南方客
南方客 2021-01-27 18:29

I tried to create a Map using folium library in python3. It work\'s fine until i add a Marker to the map. On adding Marker the output results in just a blank HTML page.

2条回答
  •  终归单人心
    2021-01-27 19:01

    in my experience, folium is very sensitive to single quotes (').

    The reason being, folium generates javascript, and transforms your strings into javascript strings, which it encloses with single quotes. It does, however, not escape any single quotes contained in the string (not even sure if that's possible in js), so having a single quote in the string has the same effect as not closing a string in python.

    Solution: Replace all single quotes in your strings with backticks (`) or (better) use @Bob Haffner's answer.


    Edit: out of sheer coincidence i stumbled over another solution just now. Apparently folium.Popup has an argument parse_html. Use it like this:

    folium.Marker([x,y], popup=folium.Popup("Foo'Bar",parse_html=True)).add_to(map)
    

    however, i could not make it work without running into a unicodeescape error. nonetheless it exists, supposedly for this purpose, and might work for you.


    Edit 2: As i've been told on github, this issue will be fixed in the next release. Ref: folium#962

提交回复
热议问题