jmcclell/django-bootstrap-pagination

KeyError: 'request'

Closed this issue · 3 comments

I was getting this error in bootstrap_pagination.py on line 148 which calls: context['request'].GET and failed because context didn't have an entry for 'request'. In fact context was a list instead of a dictionary.

The solution was to add the following to my settings.py file:

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.static",
    "django.core.context_processors.tz",
    "django.contrib.messages.context_processors.messages",
    "django.core.context_processors.request",
)

The last line is key as the rest is the default values for TEMPLATE_CONTEXT_PROCESSORS.

Please consider adding this step to the documentation.

Tested on Django 1.5.5

I wonder if this was removed at some point as a default context_processor? I don't use django much any longer and haven't done much testing beyond 1.4 for this codebase, to be honest. I'd really like someone to help take this project over since I don't do much python work any longer.

I will add this to the documentation, but it may be better to find a workaround that doesn't require a non-default context processor.

I'm rather new to django and did do some looking around for solutions to the problem beyond just adding the context processor but didn't really find anything. I would agree it's a less that ideal fix, but thanks for adding it to the docs.

In Django 1.7 and above, there's a different to set your context_processor. Thus you'd better use the following code instead of TEMPLATE_CONTEXT_PROCESSORS

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
'./templates'
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
],
},
},
]