I am working on a website. For this website I have to create a table which shows the time of the meeting and the participants of it. I am writing the code of site using Django. For the table I have a data on a .json
file. When I run the server locally it works fine and when I push it to heroku it raises FileNotFoundError
. I found this question which faces with the similar problem but the answer shows how to log something, but I need .json
file for data. My django app directory:
66 admin.py
100 apps.py
<DIR> migrations
60 models.py
3,332 schedule_of_teams.json
<DIR> static
<DIR> templates
63 tests.py
333 urls.py
807 views.py
So I have a view function in views.py
file:
def schedule_of_teams(request):
with open('./schedule_of_teams.json',encoding='utf-8') as f:
context = json.load(f)
context['title'] = 'Yarış cədvəli'
return render(request,'schedule_of_teams.html',context)
And open context manager raises the error:
FileNotFoundError at /schedule_of_teams/
[Errno 2] No such file or directory './schedule_of_teams.json/'
So why is this happening? Why it works fine when I run python manage.py runserver
with localhost but when I push to heroku it raises this exception? Is heroku ignores .json
files? By the way, I do not have *.json
on my .gitignore
file it commits the file.
What I have tried:
I tried to change the directory of the file like moving it to a folder data/
or firstly instead of open('./schedule_of_teams.json)
I wrote open('schedule_of_teams.json')
but that didn't work either.
I am literally so confused I asked this question in Python Discord Server but got no respond. One of the solutions is creating a database but I do not want to do it, since this data is just a list which has 16 dictionaries and each has 4 keys.