我正在尝试将folium
choropleth编码为StringIO
. 我基于我对相关查询的回答。我已经在这里和这里检查了答案。
AttributeError: 'bytes' object has no attribute 'encode'
视图.py
def get_choropleth(self, request):
# make choropleth ('m')
html_string = m.get_root().render()
f = StringIO(html_string)
choropleth = base64.b64decode(f.read())
choropleth = choropleth.encode('utf8') # causing error
return {'choropleth':choropleth}
经过一些反复试验,以下对我有用:
def get_choropleth(self, request):
# make choropleth ('m')
html_string = m.get_root().render()
encoded_bytes = html_string.encode('utf-8')
encoded_bytes = base64.b64encode(encoded_bytes)
encoded_bytes = encoded_bytes.decode('utf8') # decode the b64 bytes for Unicode
choropleth = encoded_bytes
return {'choropleth':choropleth}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句