[Django1.6]The MEDIA_ROOT and STATIC_ROOT settings must different 解决
2015-09-18 13:36
561 查看
该项目有一个图片上传功能,为了把上传路径很简单,写在同一个静态文件路径,于wi7执行机器上没问题,今centos我们报道了机上,如下面的错误:
django.core.exceptions.ImproperlyConfigured: The MEDIA_ROOT and STATIC_ROOT settings must have different values
google下。直接就到了django的文档中:
MEDIA_ROOT and STATIC_ROOT must
have different values. Before STATIC_ROOT was
introduced, it was common to rely or fallback on MEDIA_ROOT to
also serve static files; however, since this can have serious security implications, there is a validation check to prevent it.
文档中明白的指出MEDIA_ROOT 跟 STATIC_ROOT不能用同一个路径。
在STATIC_ROOT么有引进之前使用MEDIA_ROOT路径来存储静态文件的(css,js之类),为了安全。如今基本是使用MEDIA_ROOT
来存储上传文件,STATIC_ROOT来存储静态文件。
解决“:
settings中改动:
把MEDIA_ROOT 定义为别的路径
然后在全局的urls配置用加入
最后在页面显示图片的地方改动下连接地址就能够了。
基本上就这个三个步骤,就能替换原来的存储路径了。
本文出自 “orangleliu笔记本” 博客,转载请务必保留此出处/article/2588706.html
作者: orangleliu
django.core.exceptions.ImproperlyConfigured: The MEDIA_ROOT and STATIC_ROOT settings must have different values
google下。直接就到了django的文档中:
MEDIA_ROOT and STATIC_ROOT must
have different values. Before STATIC_ROOT was
introduced, it was common to rely or fallback on MEDIA_ROOT to
also serve static files; however, since this can have serious security implications, there is a validation check to prevent it.
文档中明白的指出MEDIA_ROOT 跟 STATIC_ROOT不能用同一个路径。
在STATIC_ROOT么有引进之前使用MEDIA_ROOT路径来存储静态文件的(css,js之类),为了安全。如今基本是使用MEDIA_ROOT
来存储上传文件,STATIC_ROOT来存储静态文件。
解决“:
settings中改动:
把MEDIA_ROOT 定义为别的路径
MEDIA_URL = '/upload/' MEDIA_ROOT = os.path.join(BASE_DIR,'uploadfiles').replace('\\','/')
然后在全局的urls配置用加入
url(r'^upload/(? P<path>.*)$','django.views.static.serve',{'document_root': settings.MEDIA_ROOT}),
最后在页面显示图片的地方改动下连接地址就能够了。
<a href="/upload/{{ user.userinfo.license }}" target="_blank">查看</a>
基本上就这个三个步骤,就能替换原来的存储路径了。
本文出自 “orangleliu笔记本” 博客,转载请务必保留此出处/article/2588706.html
作者: orangleliu
相关文章推荐
- 跨域触发事件(子页面用js触发父页面元素的事件)
- 论servlet和jsp 的区别
- jsp引入struts标签,引入自己写的jquery需要注意的问题
- POJ 2718 Smallest Difference(DFS+全排列函数)
- js数组操作
- JS 多维度星级评论
- [LeetCode 279] Perfect Squares
- 链接上的CSS应用
- django搭建Bootstrap常用问题解决方法
- JSP 生成静态HTML页面
- 基础的JavaScript编码规范
- In SQL, what’s the difference between a full join and an inner join?
- json-simple简明教程
- event.x,event.clientX,event.offsetX区别
- [CSS]学习总结
- In SQL, what is the difference between a left join and a left outer join?
- Delete Node in a Linked List
- 2015年9月17日第一节课html1-1
- JS+CSS实现TreeMenu二级树形菜单完整实例
- CommonJS规范和Nodejs模块机制