Django 静态文件配置
来源:互联网 发布:区域网络管理 编辑:程序博客网 时间:2024/06/07 07:07
Django 在自身的开发服务器上有着自身的浅蓝色排版。部署到Apache服务器上会呈现一种无排版状态。
原因是 static 静态文件没有配置。
1. 在设置文件 settings.py 里,添加:
STATIC_URL = ‘/static/’
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
#other static file. can't include STATIC_ROOT
STATICFILES_DIR = (
os.path.join(BASE_DIR, 'common_static'),
);
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
);
2. 在app所在的工程里,新建 /static,/common_static,/media 文件夹
3. 然后在 Apache 的配置文件里,需要添加以下内容:
Alias /media /path/to/media/
<Directory /path/to/media>
Require all granted
</Directory>
Alias /static /path/to/static/
<Directory /path/to/static>
Require all granted
</Directory>
WSGIScriptAlias / /path/to/prj/prj/wsgi.py
<Directory /path/to/prj/prj>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
4. cd /path/to/your project/manage.py
python manage.py collectstatic
5. 重启Apache服务器,生效。
注:
如果用的是Apache2.2版本,用以下内容替换 Require all granted 赋予权限值:
Order all, deny
Allow from all
参考:http://www.ziqiangxuetang.com/django/django-static-files.html
0 0
- Django静态文件配置
- django 静态文件配置
- Django静态文件配置
- Django静态文件配置
- django 配置静态文件
- Django静态文件配置
- django静态文件配置
- django静态文件配置
- django静态文件配置
- django静态文件配置
- django静态文件配置
- django静态文件配置
- django静态文件配置
- django静态文件配置
- django静态文件配置
- django静态文件配置
- django静态文件配置
- django静态文件配置
- 正则表达式学习总结(python版)
- Android-网络框架
- android开关屏幕
- Quartz Core 图层编程
- android framework 重启LOG分析方法
- Django 静态文件配置
- linux中某个端口拒绝远程主机连接原因及解决方法
- CentOS下JDK安装
- 购买 easy题解
- 浅析Spring中的注解
- leetcode:count and say
- Elasticsearch-PHP 快速开始
- Unity脚本中使用NGUI的预先准备
- C++STL 迭代器