可疑文件操作...连接的路径...位于基本路径组件外部 [英] Suspicious File Operation..The joined path ... is located outside of the base path component

查看:1075
本文介绍了可疑文件操作...连接的路径...位于基本路径组件外部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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


可疑文件操作在/ admin / products / productimage / add /
加入的路径(/product/images/Laptop-Computer-5_copy.png)位于基本路径组件(/ images)之外

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之前没有斜杠)
发生错误:

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


可疑文件操作在/ admin / products / produc timage / add /
加入的路径(/product/images/Laptop-Computer-5_copy.png)位于基本路径组件之外(/ Volumes / Storage / _codework / e_shop / product / images)

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')我有这个错误:

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]权限被拒绝:'/ product'

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

我已经更改了对(MacOs)的访问权限: / p>

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


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

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


chown -RK / Volumes / Storage / _codework / e_shop / static / media /

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

但没有任何帮助。
什么问题?请提供任何建议。这个问题与我之前的问题有关[a href =https://stackoverflow.com/questions/33592380/media-root-django-do-not-find-图片>请参阅

推荐答案

您已经做了一些更改,这些更改不与DB同步。我已经在实现级别进行了搜索,这不是bug。确保你使用更新的Pillow和image = models.ImageField(upload_to =whateverfolder /),然后使用python manage.py makemigrations进行同步,如果你使用1.8以上,如果你使用1.8以下的 python manage.py syncdb并且您的问题将被解决
为了将来,它习惯于同步模型。

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.

这篇关于可疑文件操作...连接的路径...位于基本路径组件外部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆