我希望能够保存通过PaletteGenForm上传的图像,方法如下:
#Form
class PaletteGenForm(forms.Form):
im = forms.ImageField(required=True)
#View
def palette_gen_view(request):
PATH_OF_IMAGE_TO_BE_PALETTED= MEDIA_ROOT+ "/tobesaved.png"
if request.method == 'POST':
form = PaletteGenForm(request.POST, request.FILES)
if form.is_valid():
im = Image.open(StringIO(request.FILES['im']['content']))
im.save(PATH_OF_IMAGE_TO_BE_PALETTED, "PNG")
#call some functions to generate pallete
return #returns the palette of the image.
else:
form = PaletteGenForm()
return render_to_response('palette_generate.html', {'form': form,})
然而,当调用此URL时,我遇到了以下错误:
'InMemoryUploadedFile' object is unsubscriptable