可疑文件操作..加入的路径...位于基本路径组件之外

Suspicious File Operation..The joined path ... is located outside of the base path component

正在尝试将 .png 文件上传到管理图像 table 我收到错误消息:

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)

这是我的设置:

  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

但是在 MEDIA_ROOT 中我添加 'product/images' (在 'product' 之前没有斜杠) 发生错误:

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)

尽管出于测试目的,我将 product/images 文件夹的副本放置在项目的根目录中。否则当斜线在产品之前时('/product/images')我得到了那个错误:

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

我已经更改了访问权限,例如 (MacOs):

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

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

但没有任何帮助。 什么问题?请给出任何 advises.This 问题与我之前的问题有关 please see

您进行了一些更改,但这些更改未与数据库同步。我在实现级别上搜索过它,这不是错误。确保您使用的是更新版本的 Pillow 和图像 = models.ImageField(upload_to="whateverfolder/"。如果您使用的是 1.8 及更高版本,则使用 "python manage.py makemigrations" 进行同步。如果您正在使用低于 1.8 执行“python manage.py syncdb,您的问题将得到解决。 为了将来养成同步模型的习惯。