April 2018
Beginner to intermediate
300 pages
7h 34m
English
I will demonstrate the workflow of creating a Django view via a simple line chart.
Inside the newly created bitcoin app folder, you should be able to find views.py, which stores all the views within the app. Let's edit it and create a view that outputs a Matplotlib line chart:
from django.shortcuts import renderfrom django.http import HttpResponse# Create your views here.from io import BytesIOimport matplotlibmatplotlib.use('Agg')import matplotlib.pyplot as plt def test_view(request): # Create a new Matplotlib figure fig, ax = plt.subplots() # Prepare a simple line chart ax.plot([1, 2, 3, 4], [3, 6, 9, 12]) ax.set_title('Matplotlib Chart in Django') plt.tight_layout() # Create a bytes buffer for saving image ...Read now
Unlock full access