Suspicious File Operation..The joined path … is lo

2019-02-26 21:49发布

问题:

Trying upload .png files into admin image table I get error:

SuspiciousFileOperation at /admin/products/productimage/add/ The joined path (/product/images/Laptop-Computer-5_copy.png) is located outside of the base path component (/images)

here is my settings :

  import os



# BASE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)))

'''path settings for django==1.8'''

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))

TEMPLATE_DIRS = (
    #'/Users/jmitch/Desktop/seven/static/templates/',
    os.path.join(os.path.dirname(os.path.dirname(BASE_DIR)), "static", "templates"),
)

# STATICFILES_FINDERS = (
#     'django.contrib.staticfiles.finders.FileSystemFinder',
#     'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#     #'django.contrib.staticfiles.finders.DefaultStorageFinder',
# )

TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            # 'DIRS': [BASE_DIR+"/templates", ],
            'DIRS': [BASE_DIR + "/static/templates/", ],
            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [
                    'django.template.context_processors.debug',
                    'django.template.context_processors.request',
                    'django.contrib.auth.context_processors.auth',
                    'django.contrib.messages.context_processors.messages',
                    'django.core.context_processors.media',
                    'django.template.context_processors.media',
                ],
            },
        },
    ]
ENV_PATH = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
MEDIA_ROOT = os.path.join(ENV_PATH, '/images')
# MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'static', 'media')
# MEDIA_ROOT = '/Volumes/Storage/_codework/e_shop/static/media/product/images/'


STATIC_ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'static', 'static-only')

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'static', 'static'),
)
# MEDIA_ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(BASE_DIR))), "static", "media")
MEDIA_URL = '/media/'
enter code here

but when in MEDIA_ROOT I add 'product/images' (without slash before 'product') an error occurred:

SuspiciousFileOperation at /admin/products/productimage/add/ The joined path (/product/images/Laptop-Computer-5_copy.png) is located outside of the base path component (/Volumes/Storage/_codework/e_shop/product/images)

although for testing purposes I placed copy of product/images folder in the root of project. Otherwise when slash is before product('/product/images')I have got that error:

OSError at /admin/products/productimage/add/[Errno 13] Permission denied: '/product'

I've changed rights for access like(MacOs):

chmod -R 777 /Volumes/Storage/_codework/e_shop/static/media/

and

chown -R K /Volumes/Storage/_codework/e_shop/static/media/

but nothing helps. What the problem?Please give any advises.This question is related to my previous question please see

回答1:

You've made some changes and those changes are not synced with DB. I've searched it on implementation level and this is no bug. Make sure you are using updated version of Pillow and image = models.ImageField(upload_to="whateverfolder/". Then sync using "python manage.py makemigrations" if you are using 1.8 and above. If you are using below 1.8 do the "python manage.py syncdb and your problem will be resolved. For future make it habit to sync models.