Django 上传文件出现 OSError Permission denied的解决办法

news/2024/7/5 6:06:43

我的服务器在Ubuntu上,使用了Apache+Nginx做App Server,Django+Python开发,今天上传文件时候出现了OSError的错误,具体原因为Permission denied

一看发现是因为上传文件的文件夹可能没有被赋予www-data用户(Apache和Nginx用户)写的权限

根据以下网站的解决办法已经解决问题了,特写此博希望能帮到大家

http://stackoverflow.com/questions/1682440/permission-denied-error-with-django-while-uploading-a-file


I just ran into this same problem. And found the solution if you are hosting with Apache as your server. For instance if my settings were:

MEDIA_ROOT = '/var/www/media/geekingreen'

then I would simply need to give that folder the correct permissions recursively to make sure that any sub-folders also have the same permission. The default group for apache is www-data so to give permission to my django app I would run these commands.

cd /var/www/media
chgrp -R www-data geekingreen/
chmod -R g+w geekingreen/

The chgrp -R www-data geekingreen/ command changes the directory geekingreen and any subdirectories to have the group www-data.
The chmod -R g+w geekingreen/ command changes what permissions the group has on all of these folders that now belong to www-data, to now have the write permission. Obviously required for uploads.

Hope this can help anyone that may have had a similar problem.




http://www.niftyadmin.cn/n/3649188.html

相关文章

[收藏]你就不是我们所需要的那种层次的领导

引用自:21世纪领导者的挑战-多样性(http://www.mindmeters.com/blogind.asp?id4)看了《Ready to Leader》,一个领导力故事。山姆(故事中的公司董事长,领导力典范)说,“如果你想改变这个世界&am…

使用Android系统自带的下拉刷新控件

首先布局: <?xml version"1.0" encoding"utf-8"?> <android.support.v4.widget.SwipeRefreshLayout xmlns:android"http://schemas.android.com/apk/res/android"xmlns:app"http://schemas.android.com/apk/res-auto"andro…

Django Admin Site (v1.4) 的Nginx配置

本人写本文是因为发现在使用NginxApache搭建完Django站点后&#xff0c;admin site显示的很丑陋。查看源码后发现&#xff0c;admin的css、js和图片都无法正常显示 baidu了一些资料&#xff0c;操作下来也不成功&#xff0c;可能是Django的版本更新的关系。所以自己写一下配置…

AIX 程序设计大赛---AIX正方形问题

AIX 程序设计大赛---AIX正方形问题作者&#xff1a;成晓旭作为“算法及实现”栏目的“抛砖引玉”之作&#xff0c;将自己2年多前实现的一个算法放出来。有一年IBM出了这个Java程序设计竞赛题&#xff0c;当时&#xff0c;自己花晚上时间用Java实现了。[问题描述]:任意给定一个正…

bootstrap4侧边栏_如何使用纯CSS和Bootstrap 4构建多个堆叠式粘性侧边栏

bootstrap4侧边栏In this tutorial you’ll work on building multiple sticky sidebars that stack without using any JavaScript. 在本教程中&#xff0c;您将构建无需使用任何JavaScript即可堆叠的多个粘性侧栏。 We’ll discuss: 我们将讨论&#xff1a; Multiple Stack…

textView相关知识

一、给textview设置颜色为#fffff 有时候我们会从服务器获得数据&#xff0c;但是后台给的服务器的值是比如&#xff1a;#B373FB 此时要想给TextView设置文字直接设置textview.setTextColor();是不行的。此时我们可以这样 String str floorcolor; int id Color.parseColor(s…

PYthon 转换HTML到Text纯文本

今天项目需要将HTML转换为纯文本&#xff0c;去网上搜了一下&#xff0c;发现Python果然是神通广大&#xff0c;无所不能&#xff0c;方法是五花八门。。。 拿今天亲自试的两个方法举例&#xff0c;以方便后人&#xff1a; 方法一&#xff1a; 1. 安装nltk&#xff0c;可以去…

如何使用vue-router设置Vue.js身份验证和路由处理

介绍 (Introduction) Vue.js is a progressive JavaScript framework for building front-end applications. Coupled with vue-router, we can build high performance applications with complete dynamic routes. Vue-router is an efficient tool and can efficiently hand…