Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server error 500 if no accept_language header is present #2179

Closed
o-zander opened this issue Aug 21, 2013 · 9 comments · Fixed by #2668
Closed

Server error 500 if no accept_language header is present #2179

o-zander opened this issue Aug 21, 2013 · 9 comments · Fixed by #2668
Assignees
Labels
Milestone

Comments

@o-zander
Copy link
Contributor

If a bot like the google bots who does not set the accept_language header is visiting the page without a language prefix and i18n is activated, following error is thrown:

NoReverseMatch: Reverse for 'pages-details-by-slug' with arguments '()' and keyword arguments '{'slug': ''}' not found.

Only happens if DEBUG is False.

@ryanbagwell
Copy link

I just spent the last 7 hours encountering this same issue. It's especially a problem when a third-party service (i.e. Instagram) tries to call a callback url without the header set.

@ryanbagwell
Copy link

I actually just figured this out, although I don't completely understand the problem.

In my case, I had set the available Django LANGUAGES setting to use only one - 'en'. However, the default LANGUAGE_CODE setting is 'en-us'. Accordingly, when requests were made without the language header were made, Django assumed it wanted a response in 'en-us'. In my case, no page actually existed in that language, because my pages only existed in 'en'.

The CMS will offer the option to localize the content for every language specified in LANGUAGES. By default, that's every language that Django supports, and results in an admin with a billion language choices. I didn't want that, which is why I set the LANGUAGES to a single choice, and ended up using the wrong language code.

@JHei
Copy link

JHei commented Nov 25, 2013

same issue here, solved it by setting LANGUAGES and LANGUAGE_CODE to matching values.

@mrsarm
Copy link

mrsarm commented Jan 30, 2014

Same issue, my languages variables are:

LANGUAGE_CODE = 'es-ar'
LANGUAGES = (
    ('es', gettext('Spanish')),
    ('en', gettext('English')),
)

Like @ryanbagwell says, looks like Django are searching a erroneous language, if the page have both language versions, no problem. Also only occurs when the user is sign-in.

Tested with the latest 3.0.0.beta3 and Python 2.7.

@digi604 digi604 added this to the 3.0 milestone Feb 10, 2014
@digi604 digi604 self-assigned this Feb 18, 2014
digi604 added a commit to digi604/django-cms that referenced this issue Feb 19, 2014
digi604 added a commit that referenced this issue Feb 19, 2014
fixes #2179 and validates that LANGUAGE_CODE is in LANGUAGES
@mrsarm
Copy link

mrsarm commented Feb 19, 2014

@digi604 , according with the official Django documentation (https://django.readthedocs.org/en/1.6.x/ref/settings.html#language-code), this is correct:

LANGUAGE_CODE = 'en-us'

An also this in the same context (https://django.readthedocs.org/en/1.6.x/ref/settings.html#languages):

LANGUAGES = (
    ('de', _('German')),
    ('en', _('English')),
)

But looking your patch, a configuration like this will be raise a ImproperlyConfigured error (digi604@92b9909#diff-9cbb78756a2eee73ef8b1d351f9d2800R197):

if not settings.LANGUAGE_CODE in dict(settings.LANGUAGES):
    raise ImproperlyConfigured(
                    'LANGUAGE_CODE "%s" must have a matching entry in LANGUAGES' % settings.LANGUAGE_CODE
                )

I'm wrong?

@digi604
Copy link
Contributor

digi604 commented Feb 20, 2014

If your LANGUAGE_CODE is 'en-us' and in your LANGUAGES you have: 'en' and 'de' then django actually supports 3 languages: 'en-us', 'en' and 'de'. The problem is that 'en-us' is not the same as 'en' and it is possible that request.LANGUAGE_CODE becomes 'en-us' if you don't have the language accept headers set. We have 2 possible solutions: Either we add LANGUAGE_CODE to CMS_LANGUAGES as well... and then you can create pages in 'en-us' and 'en' or we enforce that LANGUAGE_CODE is in LANGUAGES. To be honest i think the django docs in this regard should be updated as most people will not understand what is going on in the back and only encounter 500 after they go live and they receive a request without a accept language header and have a new language to deal with for the first time.

@digi604
Copy link
Contributor

digi604 commented Feb 20, 2014

PS. over the years i had soooo many bug reports because of this behavior that i finally decided to enforce the LANGUAGE_CODE in LANGUAGES as it makes absolutely sense in a i18n environment.

@miguelfg
Copy link

Hi, I just got this nightmare error, but I am still confused how settings.py should be configured. Mine is as follows:

LANGUAGE_CODE = 'es-ES'
from django.utils.translation import ugettext_lazy as _
LANGUAGES = (
('es', _('Spanish')),
('en', _('English')),
('de', _('German')),
)

It looks good as long as I access specifying 'Accepted-Language' header either from browser or testing it with curl. BUt wihtout a 'Accepted-Language' header , breaks with 500.

What should I tweak??

@optimum-dulopin
Copy link

Hi,
I have a similar problem, with

django-cms==3.0.2
django = 1.5.8
django-cms-search==0.6.3
whoosh < 2.5
django-haystack < 2.0

but only when I run command
./bin/django rebuild_index

I seems that it succeed to index my french pages, but them it makes and error

All documents removed.
/eggs/django_haystack-1.2.7-py2.7.egg/haystack/management/commands/update_index.py:84: UserWarning: 'SearchIndex.get_queryset' is pending deprecation & will be removed in Haystack v2. Please rename them to 'index_queryset'.
warnings.warn("'SearchIndex.get_queryset' is pending deprecation & will be removed in Haystack v2. Please rename them to 'index_queryset'.")

Indexing 534 <django.utils.functional.proxy object at 0x29a0810>.
/eggs/Django-1.5.8-py2.7.egg/django/conf/urls/defaults.py:3: DeprecationWarning: django.conf.urls.defaults is deprecated; use django.conf.urls instead
DeprecationWarning)

NoReverseMatch: Reverse for 'pages-details-by-slug' with arguments '()' and keyword arguments '{'slug': ''}' not found.

in my settings.py

LANGUAGE_CODE = 'fr'
LANGUAGES = (
('fr', _('French')),
)

what is really weird is that is I also add english language in LANGUAGES, eg :

LANGUAGES = (
('fr', _('French')),
('en', _('English')),
)
then I don't have any error any more . But I dont need english ! I was also trying with german instead of english, but then the error appear again !

thanks for help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants