在apache上部署django:找不到静态文件404

时间:2015-11-10 10:19:32

标签: python django apache http-status-code-404

我使用Apache部署我的django 但它无法读取静态文件
它会导致

  

404未找到

static
    |----static
    |       |----css
    |       |----img    
    |       |----js
    |     
    |----static-only
    |       |---css
            |---admin

这是我的静态结构:

这是我的Django项目settings.py

STATIC_URL = '/static/'
MEDIA_URL='/media/'
STATIC_ROOT=os.path.join(os.path.dirname(BASE_DIR),"static","static-only")
MEDIA_ROOT=os.path.join(os.path.dirname(BASE_DIR),"static","media")
STATICFILES_DIRS=(os.path.join(os.path.dirname(BASE_DIR),"static","static"),)

apache设置:

/etc/httpd/conf.d/django.conf

Alias /static /home/openuser/tryDjango/static

<Directory /home/openuser/tryDjango/static>
       Require all granted
</Directory>

<Directory /home/openuser/tryDjango/src/tryDjango>
       <Files wsgi.py>
               Require all granted
       </Files>
</Directory>

WSGIDaemonProcess testproject python-path=/home/openuser/tryDjango/src:/home/openuser/tryDjango/lib/python2.7/site-packages
WSGIProcessGroup testproject
WSGIScriptAlias / /home/openuser/tryDjango/src/tryDjango/wsgi.py

我发现如果我使用:

Alias /static/static_only /home/openuser/tryDjango/static/static_only
static-only下的

文件可以读取

但这仍然有问题访问:

STATICFILES_DIRS=(os.path.join(os.path.dirname(BASE_DIR),"static","static"),)

0 个答案:

没有答案