Saturday, December 20, 2014

(yet another) Custom templatetag raising KeyError when DEBUG=False

Hello all, this is a cross post i made on stackoverflow
http://stackoverflow.com/questions/27503581/yet-another-custom-templatetag-raising-keyerror-when-debug-false

I'm trying to use a custom templatetag (this one actually:
https://djangosnippets.org/snippets/2875/), on my project which works
fine as long as DEBUG=True. When it's False, the relevant error part
is:

File "...app/templatetags/helper_tags.py", line 15, in change_lang
path = context['request'].path
File "...local/lib/python2.7/site-packages/django/template/context.py",
line 56, in __getitem__
raise KeyError(key)
KeyError: 'request'

I've seen a lot of questions like this and I have already done the
settings that all of them seen to suggest which are:

1) views.py uses django.shortcuts.render:

from django.shortcuts import render
def home(request):
return render(request, 'home.html')

2) settings.py contains:

ALLOWED_HOSTS = ['*']

from django.conf import global_settings
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
"django.core.context_processors.request",
)

I've also created a new project with the same Django version (1.6.2)
that tries to imitate the problematic project as much as possible, and
for my despair it works fine also when DEBUG=False.

Any hints on this is very much appreciated.

Cheers!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALaPA7BtpQsXj%2BQPPXetq8RtaTB_RjC_jm7HDE8Zt0i_L0tc9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment