通过Django admin上传图片

时间:2014-05-20 12:41:20

标签: python django apache django-models django-admin

目前我正在使用Django 1.6.4开展Django项目以获得奖学金。我想将一些图像上传到我的apache服务器。不幸的是,我无法克服" Permission denied"填写管理页面中的表单后的消息。我的项目位于/home/nick/Workspace/Web/kleyboldt_django/下。有我的virtualenv目录和名为kleyboldt_homepage的真实项目(kleyboldt是我正在写的人的名字)。我的模型看起来像这样:

/home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/homepage/models.py

class stipendiat(models.Model):
    first_name  = models.CharField(max_length=100)
    last_name   = models.CharField(max_length=100)
    content     = models.TextField()
    year        = models.IntegerField()
    image       = models.ImageField(upload_to='stipendiaten/', default='default.jpg')

我的设置是:

/home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/kleyboldt_homepage/settings.ps

...
MEDIA_ROOT = os.path.join(BASE_DIR, 'static', 'media')

MEDIA_URL = '/media/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static', 'static-only')

STATIC_URL = '/static/'
...

/etc/apache2/apache2.conf中

WSGIDaemonProcess mks.com python-path=/home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage:/home/nick/Workspace/Web/kleyboldt_django/env/lib/python2.7/site-packages
WSGIProcessGroup mks.com

<VirtualHost *:80>
    Alias /robots.txt /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/robots.txt
    Alias /favicon.ico /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/static-only/favicon.ico

    <LocationMatch "\.(jpg|css|gif|pdf|ico)$">
        SetHandler None
    </LocationMatch>

    Alias /media/ /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/media/
    Alias /static/ /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/static-only/

    Alias /static/admin /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/static-only/admin/

    <Directory /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/static>
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>

    <Directory /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/media>
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>

    <Directory /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/static-only>
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>

    WSGIScriptAlias / /home/nick/Workspace/Web/kleyboldt_django/kleyboldt.wsgi

    ServerName mks.com

    <Directory /home/nick/Workspace/Web/kleyboldt_django/>
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>

    <Directory /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/>
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>

    <Files /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/homepage.log>
        Require all granted
        Order allow,deny
        Allow from all
    </Files>

    <Directory /home/nick/Workspace/Web/kleyboldt_django/env/lib/python2.7/site-packages/>
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/apache_error.log
    LogLevel debug
</VirtualHost>

很抱歉我写了这么多,但我想确保我没有忘记一个目录。

mks.com被重定向到我的本地计算机,其中包含/etc/hosts中的条目。

我的媒体目录的权限是:

drwxrwxrwx 4 nick www  4096 Mai 20 13:21 media

有人知道如何解决这个错误吗?

0 个答案:

没有答案