【发布时间】: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
有关【问题讨论】:
-
MEDIA_ROOT = os.path.join(ENV_PATH, 'images'),去掉斜线。 -
谢谢,@sobolevn 但还是一样(
标签: python django media-queries