Where can I find the admin code for uploading an image in django?
Question: I'm currently coding an image upload in a view and I want to compare it to the
code the admin uses for uploading images. Is there code the admin generates
the file forms from? **Where can I find the python code to an admin image/file
upload?**

I'm using ubuntu 14, python 2.7 and django 1.9.

I have been searching around in here for the admin code for uploading files,
but I cannot find it:

    
    
    /usr/local/lib/python2.7/dist-packages/django/ 
    

This is my image upload code in my view I want to compare to the admin image
upload code:

    
    
                    avatarFile=request.FILES["avatar_im"]
                    print(avatarFile)
                    for key, file in request.FILES.items():
                        path = file.name
                        path = "images/"+path
                        dest = open(path, 'w')
                        if file.multiple_chunks:
                            for a in file.chunks():
                                dest.write(a)
                        else:
                            dest.write(file.read())
                        dest.close()   
    

I'm trying to understand how my admin uploads files to my _MEDIA_ROOT/images_
, and why my code uploads to my _PROJECT_ROOT/images_ folder.

    
    
    PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__))
    
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    
    MEDIA_ROOT = os.path.join(BASE_DIR, 'static_in_pro/media')
    


Answer: I think the code used for file uploading stays inside

`django.core.files.storage.FileSystemStorage`

and

`django.core.files.move`

If you want to upload files in the directory `MEDIA_ROOT/images/` then just
use:

    
    
    import os
    from django.conf import settings
    ...
    ...
    path = os.path.join(settings.MEDIA_ROOT, 'images', file.name)
    

