I am using PIL (Python Imaging Library), and Paste to make a very simple web page. I have a function that returns just an image tag:
def home(self):
return '<img src="photo" alt="photo"/>'
And I also have a function called photo that (ideally) returns the image to be put in the img tag:
def photo(self):
img = image_from_PIL # this part works
output = StringIO.StringIO()
img.save(output, "JPEG") # saves the image as a StringIO in output
final_img = output.getvalue()
output.close()
# then set headers['content-type'] = 'image/jpeg' (confirmed this works)
return [final_img]
So I know that the image exists in the string final_img and that the content-type is “image/jpeg”. I’d expect this to work, but all I get is a 200 status OK reponse of size 0.
I tried many other things too including:
- Converting the string to binary and spitting that out
- Setting the content-length in the header to the length of the string (and x8 since each char is 8 bits)
If it makes any difference, my server is using uWSGI and nginx
I don’t know what else to try! Thanks for any help.
Do not return a list with the image, but the image itself.
Replace
with