I'm using django non-rel for appengine (djangoappengine) and have an app where the user selects an image and I have to return a crop from the selected image.
The images in my app are uploaded to the Blobstore following the django-filetransfers instructions. I've managed to upload (and even download) files just fine.
The problem I have is that I don't know how to display an image in template once it's been cropped.
The (simplified) code of my view is as follows:
def canvas_size(request):
if request.method == 'POST':
#some code here
else:
#At this point the user has selected an image, and I store its pk in session
img_file = ImageModel.objects.get(pk=request.session[SESSION_KEY]['image_pk'])
img = images.Image(blob_key=str(img_file.file.file.blobstore_info.key()))
img.resize(height=300)
img.crop(left_x=0.0, top_y=0.0, right_x=0.5, bottom_y=1.0)
crop_img = img.execute_transforms(output_encoding=images.JPEG)
#I know that the image is being cropped because if I do
#print crop_img
#I get to see the image in browser
response_dict = {
'crop_img' : crop_img,
}
template_name = 'canvas/step7.html'
response = render_to_response(template_name, response_dict, context_instance=RequestContext(request))
return response
In canvas/step7.html I've tried the following:
<img src="{{ crop_img.url }}" />
<img src="{{ crop_img.file.url }}" />
But of course that does not work.
Based on the Google AppEngine Image documentation, I know that the execute_transforms() function returns the image's encoded representation as a string. So I suppose I'm missing a step where I transform the string to a file... maybe?
Could someone point me in the right direction in order to display a crop in template using django?
Thanks for your help!