I have some french letters (é, è, à...) in a django template but when it is loaded by django, an UnicodeDecodeError exception is raised.
If I don't load the template but directly use a python string. It works ok.
Is there something to do to use unicode with django template?
You are probably storing the template in a non-unicode encoding, such as latin-1. I believe Django assumes that templates are in UTF-8 by default (though there is a setting to override this).
Your editor should be capable of saving the template file in the UTF-8 encoding (probably via a dropdown on the save as page, though this may depend on your editor). Re-save the file as UTF-8, and the error should go away.
This is from the Django unicode documentation related to your problem:
" But the common case is to read templates from the filesystem, and this creates a slight complication: not all filesystems store their data encoded as UTF-8. If your template files are not stored with a UTF-8 encoding, set the FILE_CHARSET setting to the encoding of the files on disk. When Django reads in a template file, it will convert the data from this encoding to Unicode. (FILE_CHARSET is set to 'utf-8' by default.)
The DEFAULT_CHARSET setting controls the encoding of rendered templates. This is set to UTF-8 by default. "
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With