I'm using the django_browserid
app. Here is part of my settings file.
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP
TEMPLATE_CONTEXT_PROCESSORS = TCP + (
"django.core.context_processors.request",
'django_browserid.context_processors.browserid',
)
This all works fine when DEBUG = True
. In production mode it doesn't work for one reason or another. Part of the stack trace:
return context['browserid_css'](**kwargs)
KeyError: 'browserid_css'
So it looks like the context processor isn't running. That's my guess. The only difference between the working and failing is DEBUG=True/False
.
If I debug, the value of context
in debug mode is what you would expect:
[{'False': False, 'None': None, 'True': True}, [{'False': False, 'None': None, 'True': True}, {u'csrf_token': ... etc
and in production mode:
[{'False': False, 'None': None, 'True': True}, {}]
It looks like the request is missing from the context. It also looks like this is happening when the template is loaded, not part of the request, so it's not surprising there is no request context.
Why does BrowserId only work in debug mode?
Interesting debugging session. Answering here because it's sure to happen to someone else.
The full stack trace was this:
After reconfiguring logging, it looks like I was getting an error:
This ALLOWED_HOSTS setting only applies in production mode. Django was trying to render this error and somehow rendering a template that included a BrowserID tag without a request context.
So if you get this error, first check
ALLOWED_HOSTS
.