KeyError: 'LANGUAGE_CODE'
See original GitHub issueWhile debugging a template that derives from bootstrap4.html, I noticed that the html lang attribute is not set even if I set it in my settings.py.
I’m not really sure, where this LANGUAGE_CODE should come from without loading i18n before, so I changed the bootstrap4.html like this:
<!DOCTYPE html>
{% load bootstrap4 %}
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
<html{% if LANGUAGE_CODE %} lang="{{ LANGUAGE_CODE }}"{% endif %}>
which works for me. Perhaps this could be further optimized to check if i18n is enabled but I’m not sure how to do this at the moment.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
New language adding error('Unknown language code si.')
Request URL: http://localhost.test:8000/accounts/login/. Django Version: 2.0.4. Exception Type: KeyError. Exception Value: 'Unknown language code si.'.
Read more >19811 (KeyError: u"Unknown language code 'en-us'.")
Default LANGUAGE_CODE='en-us' is not present in django.conf.locale.LANG_INFO and can trigger KeyError exception. It can be easily reproduced by using ...
Read more >KeyError when key exists in dictionary - python - Stack Overflow
I'm working on a code that detects the langue of a tweet and applies the lexical matching that language. The code USED to...
Read more >u'Unknown language code tl.' · Issue #364 - GitHub
I am getting: KeyError at /de/admin/blog/blogarticle/13/ u'Unknown language code tl.' my django version is 1.8 and python 2.7.10. and ...
Read more >Source code for pytube.captions
for backwards compatibility, e.g.: # English -> vssId: .en, languageCode: en ... try: duration = float(child.attrib["dur"]) except KeyError: duration = 0.0 ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure, or leave it out if LANGUAGE_CODEI actually like @sachalalala’s solution, but it might require django.i18n in settings.
Fixed by #53