I am hoping to have a user upload a file (a CSV) then access it in my views.py in order to use my own code to read it. However, I keep getting the error:
[Errno 2] No such file or directory: 'D:/media/data.csv'
For reference, my project is stored under the following directory on my PC:
D:\Python\[PROJECT_NAME]
Here is what my settings.py looks like:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
and my views.py:
import os
from django.conf import settings
def create_chart(request):
...
file = File.objects.get(id=4)
file_ = open(os.path.join(settings.MEDIA_ROOT, file.file.url))
If I go into my admin, I can click on an entry and access the file. However when trying to get it in views.py it is a no go. I am absolutely befuddled by this issue and any help would be appreciated.