[Answer]-Putting utf-8 dict in Django template

1👍

✅

Assuming you are using Python 2, the problem is that you are reading the file as a byte string and not a Unicode string. I believe ast handles utf-8 fine, so you can simply do:

with open(os.path.join(FS_ROOT, FAQ_FILE)) as q: FAQ = ast.literal_eval(q.read().decode('utf-8'))

Or use codecs.open to open the file with the correct encoding.


If ast doesn’t like your Unicode characters, you can call decode() on the strings before passing them to Django.


If you are using Python 3, the problem is probably that the encoding isn’t utf-8, in which case using codecs as above should work, provided you use the correct encoding.

Leave a comment