3

I've looked at all the other solutions but nothing seems to work for me. I have this in my settings.

MEDIA_ROOT = '/Desktop/myapp/media/'
MEDIA_URL = 'http://127.0.0.1:8000/media/'

This in my admin.py

    image = models.FileField(upload_to='images/')

I am running this on the localhost server at the moment. When I try to upload an image in admin and save it, I get the error:

[Errno 13] Permission denied: '/Desktop'

I've tried changing the mode using chmod and chown, but I still get the same error. I have even checked lsof -i and Python does seem to have access to this folder. What am I doing wrong?

4

2 回答 2

10

我只是在绝对路径上遇到了同样的问题,但我意识到了别的东西。我正在加入这样的道路:

os.path.join(BASE_DIR, "/media")

但是,如文档所述:

如果组件是绝对路径,则所有先前的组件都将被丢弃,并从绝对路径组件继续连接。

所以删除根斜线解决了这个问题:

os.path.join(BASE_DIR, "media")

干杯。

于 2015-04-07T15:03:49.893 回答
7

好吧,我似乎已经回答了我自己的问题。事实证明,这是一个非常小的问题。我所做的只是将媒体根目录更改为完整路径,瞧。

MEDIA_ROOT = 'Users/username/Desktop/myapp/media/'
于 2013-09-11T10:03:33.953 回答