Creating marker on map using Folium results in blank HTML page

╄→гoц情女王★ 提交于 2019-11-29 17:49:48

@MCO is absolutely correct.

I like to leverage html.escape() to handle the problem characters like so

import folium
import html

map = folium.Map(location=[20.59,78.96], tiles = "Mapbox Bright")

folium.Marker([26.80,80.76],popup=html.escape("Hey, It's Moradabad")).add_to(map)
map.save("mapOutput.html")

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!