【问题标题】:Suspicious File Operation..The joined path ... is located outside of the base path component可疑文件操作..连接路径...位于基本路径组件之外
【发布时间】:2016-02-11 01:06:30
【问题描述】:

尝试将 .png 文件上传到管理图像表中我收到错误:

SuspiciousFileOperation 在 /admin/products/productimage/add/ 连接路径 (/product/images/Laptop-Computer-5_copy.png) 位于基本路径组件 (/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 中时,我添加了“产品/图像”(“产品”之前没有斜线) 发生错误:

SuspiciousFileOperation 在 /admin/products/productimage/add/ 连接路径 (/product/images/Laptop-Computer-5_copy.png) 位于基本路径组件 (/Volumes/Storage/_codework/e_shop/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/

但没有任何帮助。 什么问题?请给任何建议。这个问题与我之前的问题please see

有关

【问题讨论】:

标签: python django media-queries


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2019-12-03
    • 2019-04-14
    • 1970-01-01
    • 2019-07-08
    • 2021-02-01
    • 1970-01-01
    • 2014-09-07
    • 2022-07-14
    • 2016-09-11
    相关资源
    最近更新 更多