1 year ago
#366749
azowad
How can I read csv files from the link stored in django model within views file?
I am creating a map with Folium, Django and Pandas. I created a django model where I store my csv file's url. I want to read csv files from there dynamically so that I can use different data dynamically. How can I do that? I used a url of a csv file. I want to make it dynamic so that I can fetch one from models directly. Here is my code. I will be very grateful for your assistance.
def mapview(request, map_pk):
srlist = Map.objects.filter(pk=map_pk)
bd = pd.read_csv("https://docs.google.com/spreadsheets/d/1IohEgJi8ajDoHyPF315vi13F3m0vDtbl7DzmSmtUHpA/gviz/tq?tqx=out:csv")
df = pd.DataFrame(bd)
lat = df[['lat']]
lng = df[['lng']]
m = folium.Map(title='Bangladesh', location=[23.7805733, 90.2792399], zoom_start=7)
for i, row in df.iterrows():
folium.Marker(location=[row['lat'], row['lng']]).add_to(m)
m = m._repr_html_()
context = {
'm':m,
'bd':bd,
'lat': lat,
'lng': lng,
'srlist':srlist,
'df':df,
}
return render(request, 'map/mapview.html', context)
django
django-models
django-views
folium
0 Answers
Your Answer