Create json config file & update templates
This commit is contained in:
parent
2f4a23b600
commit
c0b47b0739
12 changed files with 80 additions and 63 deletions
21
gallery/context_processors.py
Normal file
21
gallery/context_processors.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
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}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue