我应该怎么做才能在更新视图中获取与要更新的对象相对应的文件?
我已经使CreateView可以发布最多包含20个文件的对象Session,并且可以正常工作,无论是1个文件还是10个文件都没有关系。 但是我不知道如何以UpdateView的形式显示创建的文件
import folium
import branca
from folium import plugins
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv(r"C:\Users\VinitJ\Documents\lat_long.csv")
df.head()
df
legend_html ="""
<table width = 100%, style="font-size: 20px;">
<tr><td style="color:blue">Less than equal to 50 <i class="fa fa-map-marker fa-2x"
style="color:blue"></td>
<td style="color:green">between 50 to 100    <i class="fa fa-map-marker fa-2x"
style="color:green"></td>
<td style="color:yellow">between 100 to 200    <i class="fa fa-map-marker fa-2x"
style="color:yellow"></td>
<td style="color:orange">above 200    <i class="fa fa-map-marker fa-2x"
style="color:red"></td>
</table>
"""
folium.Element(legend_html)
m = folium.Map([39.4133, -105.7567], zoom_start=5,width = 5000, height = 2500, top = 20)
m.get_root().html.add_child(folium.Element(legend_html))
#for index, row in df.iterrows():
# folium.Marker([row['lat'], row['lon']],
# #popup=row['City','COUNTRY'],
# icon=folium.Icon(icon='')
# ).add_to(m)
#m.save('map4.html')
#m.get_root().html.add_child(folium.Element(legend_html))
#df.rename(columns={'Peering DB code':'PeeringDBcode','SITE CODE':'SITECODE','SITE ADDRESS':'SITEADDRESS','Site Type':'SiteType','IP PoP Status':'IPPoPStatus','IP SLA':'IPSLA','In Service Date':'InServiceDate'},inplace =True)
def fancy_html(row):
i = row
city = df['city'].iloc[i]
Value = df['value'].iloc[i]
left_col_colour = "#2A799C"
right_col_colour = "#C5DCE7"
html = """<!DOCTYPE html>
<html>
<head>
<h4 style="margin-bottom:0"; width="300px">{}</h4>""".format(city) + """
</head>
<table style="height: 126px; width: 300px;">
<tbody>
<tr>
<td style="background-color: """+ left_col_colour +""";"><span style="color: #ffffff;">Top PLot</span></td>
<td style="width: 200px;background-color: """+ right_col_colour +""";">{}</td>""".format(city) + """
</tr>
<tr>
<td style="background-color: """+ left_col_colour +""";"><span style="color: #ffffff;">Value</span></td>
<td style="width: 200px;background-color: """+ right_col_colour +""";">{}</td>""".format(Value) + """
</tr>
</tbody>
</table>
</html>
"""
return html
#location = df['lat'].mean(), df['lon'].mean()
#m = folium.Map(location=location,zoom_start=15,min_zoom=5)
#for i in range(0,len(df)):
# html = fancy_html(i)
#
# iframe = branca.element.IFrame(html=html,width=400,height=300)
# popup = folium.Popup(iframe,parse_html=True)
#
# folium.Marker([df['Latitude'].iloc[i],df['Longitude'].iloc[i]],
# popup=popup,icon=folium.Icon(color=color, icon='info-sign')).add_to(m)
#
text =df['value']
for i in range(0,len(df)):
num_of_casualties = df['value'].iloc[i]
if num_of_casualties <= 50:
color = 'blue'
elif num_of_casualties <= 100:
color = 'green'
elif num_of_casualties <= 200:
color = 'yellow'
else:
color = 'red'
html = fancy_html(i)
iframe = branca.element.IFrame(html=html,width=400,height=200)
popup = folium.Popup(iframe,parse_html=True)
#folium.map.Marker(
#[df['lat'].iloc[i],df['lon'].iloc[i]],
#icon=DivIcon(
# icon_size=(150,36),
# icon_anchor=(0,0),
# html='<div style="font-size: 24pt">%s</div>' % text,
# )
# .add_to(m)
folium.CircleMarker([df['lat'].iloc[i],df['lon'].iloc[i]],radius=12,color=color,
popup=popup,fill_color=color).add_to(m)
#m.get_root().html.add_child(folium.Element(legend_html))
m.save('map21.html')
我可以在没有图像的情况下更新Session对象