If a user uploads an image, and I resize it using PIL, I get a PIL Image object.
How do I display a PIL Image file in a template, before it has been saved to the database? Can it even be passed in as an image and rendered?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For a limited set of browsers, you can base64 encode the image and use inline images. See Embedding Base64 Images.
A solution that works for all browsers is an image tag referencing a view that returns the image.
[update]
Well… When you use
<img src="foo">, foo is always retrieved by a GET perhaps that is why it is not working – request.FILES will not be available in a GET request. If you open firebug or the chrome debug toolbar, in the network tab, you will see the POST request with the uploaded image and after that a GET request to fetch the image.You have to save the image somewhere between both steps.
Popular choices are redis and memcached. You can think of them as giant shared python dict with an expire date. If the images are small, like an avatar, you can also save the image data in a session variable.