mercredi 25 mars 2015

Trouble displaying generated image in Django

View:



import numpy as np
import matplotlib.pyplot as plt
import os


def blah_view(request):

# BUILD GRAPH
fname = "blah.png"
path = "home/templates/images"
fullpath = os.path.join(path, fname)

# 7 different groups
ind = np.arange(7)
width = 0.35

fig, ax = plt.subplots()

# code omitted. Generate graph here

plt.savefig(fullpath)

return render_to_response("image.html", {"path": fullpath})


image.html:



<img src="{{ path }}" />


urls.py:



url(r'^blah$', blah_view, name="blah")


If I try to navigate to /blah, I get a 404 error when trying to render the image. I'm stumped. The image is in the correct path and exists.


I get a 404 error that 127.0.0.1:8000/home/templates/home/blah.png not found.


How can I display my generated image? Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire