我正在尝试渲染:
我已经成功渲染了直方图,但是没有渲染Folium地图。取而代之的是, results.html 加载了NONE
,我希望在该位置上可以找到Folium地图。
我不确定是否可以将HTML include标签用于属性实例方法?
Models.py
class Hashtag(models.Model):
def display_locations(self):
""" Function to create a dict by frequency of the locations associated with search_text """
country_list = list(self.location.values_list('country', flat=True).all())
for country in country_list:
location_freq = {i:country_list.count(i) for i in set(country_list)}
return location_freq
@property
def get_histogram(self):
""" Function to create and save histogram of Hashtag.locations """
location_freq = self.display_locations()
plt.bar(list(location_freq.keys()), location_freq.values(), color='g')
plt.show()
plt.savefig('mapping_twitter/static/mapping_twitter/images/histogram/histogram.png')
@property
def get_heatmap(self):
""" Function to create and save heatmap of Hashtag.locations """
location_map = folium.Map(
location=[51.5074, 0.1278],
tiles="Stamen Terrain",
zoom_start=12)
location_map.save('mapping_twitter/templates/mapping_twitter/heatmap.html')
Results.html
<h3>Histogram</h3>
<div class="boxed">
<p>
{{ hashtag.get_histogram }}
<img src="{% static 'mapping_twitter/images/histogram/histogram.png' %}" />
</p>
</div>
<h3>Heatmap</h3>
<div class="boxed">
<p>
{{ hashtag.get_heatmap }}
{% include 'mapping_twitter/heatmap.html' %}
</p>
</div>