1. 在django项目根目录下创建/collectedstatic/文件夹##
2. 配置apache2配置, 我的配置如下##
<VirtualHost *:80>
ServerName mysite
Alias /static/ /home/ivan/workspace/mysite/myWebSite/collectedstatic/
WSGIScriptAlias / /home/ivan/workspace/mysite/myWebSite/myWebSite/wsgi.py
<Directory /home/ivan/workspace/mysite/myWebSite/collectedstatic/>
Order deny,allow
Allow from all
Options -Indexes FollowSymLinks
</Directory>
</VirtualHost>
3.在django setting下配置STATIC_ROOT项,使其指向/collectedstatic文件夹##
我的部分setting配置
STATIC_URL = '/static/'
SITE_ROOT = os.path.dirname(os.path.abspath(__file__))
SITE_ROOT = os.path.dirname(os.path.join(SITE_ROOT, '../'))
STATIC_ROOT = os.path.join(SITE_ROOT, 'collectedstatic')
4.在项目下运行python manage.py collectstatic命令
5.reload apache2, 运行sudo service apache2 reload
来源:oschina
链接:https://my.oschina.net/u/2354617/blog/615971