I am new to python and Django but have a bit of code that works in displaying my graph but as a separate popup window. I am calling this line of code from my HTML page:
{% block content %}
<h1>Title: {{ report.title }}</h1>
<div>
{{ report.show_graph }} //THIS PORTION IS CALLING THE GRAPH WHICH IS RESULTING IN A POPUP OF IT IN A SEPARATE WINDOW
</div>
<p><strong>Summary:</strong> {{ report.summary }}</p>
<p>Date Created: {{ report.date_created }}</p>
{% endblock %}
It triggers a request and calls the graph but as a separate standalone window. The code I am calling is:
class Report(models.Model):
"""Model representing a report"""
title = models.CharField(max_length=200)
date_created = models.DateField("Date", default=datetime.date.today)
summary = models.TextField(max_length=1000, help_text='Enter a brief summary of the report.')
def __str__(self):
"""String for representing the Model Object"""
return self.title
def get_absolute_url(self):
"""Returns the url to access a digital record of this Report"""
return reverse('report-detail', args=[str(self.id)])
def show_graph(self):
style.use('ggplot')
pfizer_data = quandl.get("NSE/PFIZER", authtoken="....")
pfizer_data['Close'].plot()
return plt.show()
I am trying to have the graph be returned as HTML so it is embedded in the div instead of a separate window. Thanks.