You can achieve this using middleware before touching the view,
class ModelMiddleware(object):
"""
Model data
"""
def process_request(self, request):
# Fetch your data
# Append var data to request
request.META['VAR'] = [1, 2, 3]
return None
You can get the VAR in view using request,
def veiw_data(request, ):
print request.META['VAR']
Here is How to set django middleware in settings file
Update:
If you want to call the sql only first time project loads use this way,
I imagined my project structure this way,
mysite/
mysite/
__init__.py --> Add the logic in this file,
urls.py
settings.py
test.py
manage.py
__init__.py
from catalog.models import Product
import settings
settings.VAR = Product.objects.all()
Done. You can access the VAR in your project. Hope this may be helpful