When
locale.getlocale()
locale.getdefaultlocale()
sys.getfilesystemencoding()
sys.getdefaultencoding()
is run through manage.py shell, I get
('en_US', 'UTF-8')
('en_US', 'UTF-8')
utf-8
utf-8
Which fits my locales:
LANG=en_US.UTF-8
LANGUAGE=en_US:
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
However, when the request is handled by Apache/Nginx it produces:
(None, None)
(None, None)
ascii
utf-8
This leads to several UnicodeDecodeErrors throughout my site and I failed to find the reason for the mismatch.
Neither setting AddDefaultCharset utf-8 for Apache or charset utf-8; for Nginx solved the issue.