Reputation: 69
I have hosted my python + django project on pythonanywhere.com and I have encountered a problem, when I want to save an item with an image. All other fields of item
are saving, but the image isnt.
Here's the whole error:
PermissionError at /admin/core/bike/add/
[Errno 13] Permission denied: '/home/omega/resizedComm/media_root/bikes/xx.png'
My settings:
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static_in_env')]
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media_root')
What can be causing this error?
Ok, so when I change the MEDIA_ROOT
to different path it actually works (it creates the folder and upload images there), but it crashes when I am trying to save the image to the oryginal media_root
. Any ideas?
Upvotes: 0
Views: 6340
Reputation: 7332
Your error and the output of ls would suggest that the folder you are trying to write to, does not have write permissions.
Either manually, or through code you'll need to grant write permissions. If your code is running as omega, then chmod u+w <folder path>
should do it. In python, chmod with the numeric code 755 should do it.
import os
os.chmod(<folder path>, 755)
Upvotes: 3