1👍
Well, I did not find to solution to why it doesn’t work, but I did find a solution that does work. Hopefully this can help others or it may give a clue to someone why the original method failed.
I made the following changes:
Template:
{% for fn in jpg_names %}
<img src="/tools/returnImage/{{ fn }}">
{% endfor %}
URLS:
urlpatterns = patterns('ri.tools.views',
url(r'^$', 'index', name="index"),
url(r'defineParameters','defineParameters',name='defineParameters'),
url(r'downloadcsv','downloadcsv',name='downloadcsv'),
url(r'downloadpdf','downloadpdf',name='downloadpdf'),
url(r'downloadZipFile','downloadZipFile',name='downloadZipFile'),
url(r'returnImage/.*','returnImage',name='returnImage'),)
Views:
def returnImage(request):
path = "/opt/local/var/media/facstool/"
_, fn = os.path.split(request.META['PATH_INFO'])
f = open(str(path)+fn,'rb')
img = f.read()
f.close()
os.remove(str(path)+fn)
response = HttpResponse(img,mimetype='image/jpeg')
return response
Basically this adds the filename to the img tag, then strips off the filename in the view, opens it on the server, reads it into a variable, deletes the original file and returns the image. It is the behavior I wanted, I just don’t understand why the OP wouldn’t have worked.
Source:stackexchange.com