[Answer]-Django UnicodeDecodeError

1👍

This part of the traceback:

File "C:\Python27\lib\site-packages\django\template\loaders\filesystem.py" in load_template_source
  38.                     return (fp.read().decode(settings.FILE_CHARSET), filepath)

indicates that the error occurred while loading the template from the disk, not while rendering the template.

In addition, the error message:

Exception Value: 'utf8' codec can't decode byte 0x85 in position 702

indicates that the problem is in position 702 of the file. However, your pasted students.html is only about 560 bytes. Therefore, either you haven’t pasted the entire file, or it’s actually reading a different file than the one you think.

0👍

I think you have a problem with template file encoding. Try to open it without any data (empty student_list, some dummy schoolclass). If it will be still throwing an error, the problem is a template file itself so you just need to save it with you editor forcing utf-8.

Otherwise, if it will work fine with an empty context, you need to look for badly-encoded entries in your db. For this you can write a loop and check student_list elements one-by-one.

0👍

I should also point out that you might also get this error if there is any non-ascii character in your file path. Say something like:

D:\säga\något\my_project\templates

Renaming the file to include only ascii characters should solve the problem.

0👍

I changed encoding on my main base html file to UTF16 which resulted to the error in template rendering that is the and this changed the file encoding settings. Yes, I ran into the error then landed here antonis helped me solve the mess, by forcing the encoding to utf 8 just by using my editor (pycharm) on the bottom part there is encoding settings, just convert the current encoding to utf 8 and the error will be gone

Leave a comment