私はappengine(djangoappengine)にdjango non-relを使用しており、ユーザーが画像を選択するアプリがあり、選択した画像から切り抜きを返す必要があります。
私のアプリの画像は、 django- filetransfers instructions に従って Blobstore にアップロードされます。ファイルを正常にアップロード (およびダウンロード) することができました。
私が抱えている問題は、トリミングされた画像をテンプレートに表示する方法がわからないことです。
私のビューの(簡略化された)コードは次のとおりです。
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
canvas/step7.html で、次のことを試しました。
<img src="{{ crop_img.url }}" />
<img src="{{ crop_img.file.url }}" />
しかし、もちろんそれはうまくいきません。
Google AppEngine Image documentationに基づいて、execute_transforms() 関数が画像のエンコードされた表現を文字列として返すことを知っています。だから、文字列をファイルに変換するステップが欠けていると思います...多分?
djangoを使用してテンプレートにクロップを表示するために、誰かが私を正しい方向に向けることができますか?
ご協力いただきありがとうございます!