1

I am trying to implement a context_processor in Django via a custom app. I am failing due to Module not found error.

My app name is brand.

My context processer looks like this:

from .models import ContactDetail

def contact(request):
    contact = ContactDetail.objects.first()
    return { 'contact' : contact }

My app is included in installed apps and the model has been migrated.

I have included my context processor into the context_processors list as per documentation:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'mysite', 'templates'),],
        'OPTIONS': {
            'context_processors': [
                'brand.context_processors.contact',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.i18n',
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.template.context_processors.media',
                'django.template.context_processors.csrf',
                'django.template.context_processors.tz',
                'sekizai.context_processors.sekizai',
                'django.template.context_processors.static',
                'cms.context_processors.cms_settings',
            ],
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
                'django.template.loaders.eggs.Loader'
            ],
        },
    },
]

The Error I am getting is:

Django Version: 1.11.16
Exception Type: ModuleNotFoundError
Exception Value: No module named 'brand.context_processors'

I have tried searching for solutions but most of the questions are for previous versions of django ( <= 1.8 ) I am using 1.11.16.

I have read through the docs and it is unclear what I am missing.

Any help is apreciated.

Daniel Tate
  • 2,075
  • 4
  • 24
  • 50

1 Answers1

0

Make sure that you named that file context_processors.py and placed in myapp directory.

ajinzrathod
  • 925
  • 10
  • 28