Django 使用django filer上传图片

前言

木有前言

注意

django-filer目前只支持到django 1.11

setting.py

INSTALLED_APPS = [
    # image support
    'easy_thumbnails',
    'filer',
    'mptt',
]

# Image Upload Support
THUMBNAIL_HIGH_RESOLUTION = True
THUNMNAIL_PROCESSORS = {
    'easy_thumbnails.processors.colorspace',
    'easy_thumbnails.processors.autocrop',
    'easy_thumbnails.processors.scale_and_crop_with_subject_location',
    'easy_thumbnails.processors.filters',
}
FILER_STORAGES = {
    'public': {
        'main': {
            'ENGINE': 'filer.storage.PublicFileSystemStorage',
            'OPTIONS': {
                'location': os.path.join(BASE_DIR, 'static/media/filer'),
                'base_url': '/media/filer/'
            },
            'UPLOAD_TO': 'filer.utils.generate_filename.randomized',
            'UPLOAD_TO_PREFIX': 'filer_public'
        },
        'thumbnails': {
            'ENGINE': 'filer.storage.PublicFileSystemStorage',
            'OPTIONS': {
                'location': os.path.join(BASE_DIR, 'static/media/filer_thumbnails'),
                'base_url': '/media/filer_thumbnails/',
            }
        }
    },
    'private': {
        'main': {
            'ENGINE': 'filer.storage.PublicFileSystemStorage',
            'OPTIONS': {
                'location': os.path.join(BASE_DIR, 'static/smedia/filer'),
                'base_url': '/smedia/filer/'
            },
            'UPLOAD_TO': 'filer.utils.generate_filename.randomized',
            'UPLOAD_TO_PREFIX': 'filer_public'
        },
        'thumbnails': {
            'ENGINE': 'filer.storage.PublicFileSystemStorage',
            'OPTIONS': {
                'location': os.path.join(BASE_DIR, 'static/smedia/filer_thumbnails'),
                'base_url': '/smedia/filer_thumbnails/',
            }
        }
    }
}

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/upload/media')