[Solved]-Django: AttributeError: 'NoneType' object has no attribute 'split'


base_lang = get_language().split('-')[0]

This line is a bug in Django 1.8. It was fixed as part of 1.8.1:

Prevented TypeError in translation functions check_for_language() and get_language_bidi() when translations are deactivated (#24569).

You should upgrade to the latest 1.8.x release, 1.8.8. at the time of writing. That will fix this bug and others.

Minor releases only contain bugfixes and security patches, so you should always upgrade to the latest minor release for whatever major version you’re using.



try to activate a language in your page view:

from django.utils import translation

def page(request, slug='index'):
    """ Render the requested page if found """
    file_name = '{0}.html'.format(slug)
    page = get_page_or_404(file_name)
    context = {'slug': slug, 'page': page} 
    translation.activate('en') # <------- Activate language EN
    return render(request, 'page.html', context) 

it is because context processor is trying to get the context language and it is obviously None.


ok, this is a bug in 1.8 as knbk said, so you need to upgrade it to new version..

Leave a comment