Django: resize image before upload

i want to resize image(Pillow) before upload, i write below code but not work!
and get error:

AttributeError at /myapp/list/


Request Method: POST

Request URL:
Django Version: 1.8 Exception Type: AttributeError Exception Value:


Exception Location:


in getattr, line 622 Python Executable: /usr/bin/python3.4 Python
Version: 3.4.0

def list(request):
# Handle file upload
if request.method == 'POST':
    form = DocumentForm(request.POST, request.FILES)
    if form.is_valid():
        imga = request.FILES['docfile']
        size = (600, 400)
        im =
        imga = im.resize(size)
        request.FILES['docfile'] = imga
        newdoc = Document(docfile = request.FILES['docfile'], namefile=request.POST['namefile'])

        # Redirect to the document list after POST
        return HttpResponseRedirect(reverse('myproject.myapp.views.list'))
    form = DocumentForm() # A empty, unbound form

# Load documents for the list page
documents = Document.objects.all()

# Render list page with the documents and the form
return render_to_response(
    {'documents': documents, 'form': form},

Source: python

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.