In my django project, I need to pass certain details from couple of models to all the views and realized that the best way to do this would be create a custom context processor file.
the context processor works fine when passing harcoded values but throws django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
when trying to import model in the context processor file.
project structure:
accounts_engine
| migrations
| admin.py
| apps.py
| custom_processor.py
| forms.py
| models.py
| tests.py
| urls.py
| views.py
models.py
class Role(models.Model):
name = models.CharField(max_length=200)
settings.py
from accounts_engine import custom_processor
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'accounts_engine.custom_processor.general_details',
],
},
},
]
accounts_engine/custom_processor.py
def general_details(request):
return {'some_key1': 'some_value1', 'some_key2': 'some_value2'}
this works fine but fails when I import account_engine.models.py here