13๐
Try checking the permissions on each directory in the path starting at /. Just a thought.
79๐
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.
- [Django]-Reverse for '*' with arguments '()' and keyword arguments '{}' not found
- [Django]-How to create a user in Django?
- [Django]-Django: get unique object list from QuerySet
4๐
Just in case you run into this when running your development server.
I ran the development server as root like this: sudo python manage.py runserver 0.0.0.0:80
in order to test the site with an iPad in the same LAN network.
The cache files generated in that session belonged to root. So when I ran the project the next day NOT as root I got the permission denied error.
- [Django]-How does the get_or_create function in Django return two values?
- [Django]-Import error cannot import name execute_manager in windows environment
- [Django]-TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
3๐
mkdir(name, mode)
Exception Type: OSError at /admin/products/photo/add/
but your application is deployed at
/var/www/django_projects/gangr/../gangr/
Do you have a directory path set to an absolute path โ/admin/products/photo/add/โ rather than something relative like โadmin/products/photo/add/โ?
Check the MEDIA_ROOT and MEDIA_URL in your settings.py file.
http://docs.djangoproject.com/en/dev/ref/settings/#media-root
- [Django]-How to send email via Django?
- [Django]-How do I get user IP address in Django?
- [Django]-Silence tqdm's output while running tests or running the code via cron
2๐
You had to modify the permissions and owner settings in order for your app to be able to upload media files.
You should run these commands to grant permission to your Django app as the default group for Apache is www-data.
sudo groupadd www-data
sudo adduser www-data www-data
sudo chgrp -R www-data media
sudo chown -R www-data media
sudo chmod -R 770 media
By doing so, a new user group called "www-data" is created, the user "www-data" is added to it, the user group of the media is changed to "www-data," and finally the owner privileges are changed to "770," granting read, write, and execute rights to the owner (root) and owner group (www-data), but denying access to anyone else. Now that www-data is a member of the www-data group, it has the ability to read and write.
- [Django]-Web application monitoring best practices
- [Django]-Django: OperationalError No Such Table
- [Django]-How to automatically destroy django test database
0๐
This is a permission issue and you have to understand linux permissions. The other answers will probably help you with that. BUT one another important point. If you deploy the web app using Apache, the changes does not take effect unless you restart apache by: systemctl restart apache
. So basically if you fix the ownership/permissio using your linux knowledge and restart apahce after that you can fix the problem.
- [Django]-Django โ run a function every x seconds
- [Django]-Django โ how to make ImageField/FileField optional?
- [Django]-Alternative to the deprecated setup_environ() for one-off django scripts?