如何在Webfaction上配置带有upload_to和MEDIA_ROOT的Django ImageField? [英] How do you configure a Django ImageField with upload_to and MEDIA_ROOT on Webfaction?

查看:106
本文介绍了如何在Webfaction上配置带有upload_to和MEDIA_ROOT的Django ImageField?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在django项目中有以下模型字段:

I have the following model field in a django project:

headshot = models.ImageField(upload_to='/tmp', blank=True, null=True)



settings.py



settings.py

# format                                    <project>/<app>
MEDIA_ROOT = '/home/username/webapps/django/myproject/books/media/'

我创建了一个目录: / home / username / webapps / django / myproject / books / media / tmp 并给它 chmod 777 权限。

I have created a directory: /home/username/webapps/django/myproject/books/media/tmp and gave it chmod 777 permissions.

当我尝试添加新图片时,我收到以下错误:

I get the following error when I try to add a new image:

SuspiciousOperation at /admin/books/author/add/
Attempted access to '/tmp/Comment.png' denied.
Request Method: POST
Request URL:    http://username.webfactional.com/app/admin/books/author/add/
Django Version: 1.3.1
Exception Type: SuspiciousOperation
Exception Value:    
Attempted access to '/tmp/Comment.png' denied.
Exception Location: /home/username/webapps/django/lib/python2.7/django/core/files/storage.py in path, line 234
Python Executable:  /usr/local/bin/python
Python Version: 2.7.1

有谁知道我在做错什么?我需要 .htaccess 或其他一些设置可以写入这个目录或Django配置有问题吗?

Does anyone know what I'm doing wrong? Do I need .htaccess or some other settings to be able to write to this directory or is there something wrong with my Django config?

我仍然想知道要使用哪些 chmod 值,以及如何设置 MEDIA_URL 。我想我可能需要在 urls.py 中为 MEDIA_URL 做一些事情。

I would still like to know what chmod values to use and how to set MEDIA_URL. I'm thinking I might need to do something in urls.py for MEDIA_URL.

我的项目是在webhost Webfaction上设置的,如果这有所作为。

My project is set up on the webhost Webfaction if that makes a difference.

推荐答案

修正它。似乎答案是使用upload_to ='tmp'而不是upload_to ='/ tmp'。

Fixed it. Seems like the answer was to use upload_to='tmp' instead of upload_to='/tmp'.

这篇关于如何在Webfaction上配置带有upload_to和MEDIA_ROOT的Django ImageField?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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