I can read a.txt
file like this:
text = open('a.txt', 'rb').read()
But when I put the a.txt
to the media
folder, this doesn't work:
text = open('/media/a.txt', 'rb').read()
I'm getting the following error:
IOError at /
[Errno 13] file not accessible: '/media/a.txt'
How can I read file from the media
directory?
To be more generic (and be sure that you use the media folder), you could change it to:
import os
from django.conf import settings
text = open(os.path.join(settings.MEDIA_ROOT, 'a.txt'), 'rb').read()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With