[Django]-Disable django context processor in django-admin pages

5👍

You’ll have to detect if the request is for admin pages and skip what you want to in your context processor.

def my_context_processor(request,*args,**kwargs):
    if 'admin' in request.META['PATH_INFO']:
        return {}
    else:
        # do something here

9👍

Following up on Dhiraj’s answer, which works if your system uses the default (English/non-translated) URLs, and for the sake of those us who do use localised URLs, I found the following snippet to do the trick in the easiest manner (relevant to Django 1.10 and later, not tested on earlier versions).

from django.urls import reverse
if request.path.startswith(reverse('admin:index')):
    return {}
else:
    # do stuff relevant to non-admin pages

Leave a comment