I have a JSON file that lives outside my django project folder and I want to read it and use it in my index.html which is inside my django project folder.
I read somewhere that I can pass files through views.py
(I am using CreateView
as my index.html), but I can't find it anymore.
I found this but it doesn't give any explanation. Can anyone send me a keyword or a hint to find it in the documentation or I can google for, I'm kind of lost right now?
Thanjks in advance!
EDIT
Thanks to Chathan Driehuys and this and this I found out how to read a JSON and load it into the dictionary. Here's my setup:
import json
class MyCreateView(CreateView):
def get_context_data(self, **kwargs):
context = super(MyCreateView, self).get_context_data(**kwargs)
with open('/path/to/my/JSON/file/my_json.cfg', 'r') as f:
myfile = json.load(f)
context['my_json'] = my_data