import json from pathlib import Path from django.conf import settings from django.core.cache import cache def site_config(request): config = cache.get('site_config') if not config: config_path = Path(settings.BASE_DIR) / 'config' / 'site_config.json' try: with open(config_path, 'r') as f: config = json.load(f) cache.set('site_config', config, 3600) except FileNotFoundError: config = {} return {'site_config': config}