'utf-8' codec can’t Decode byte 0xe1 in position in rendering html

Asked

Viewed 157 times

0

Greetings to all.

I am trying to render an html file with Python/Django and am getting error "'utf-8' codec can’t Decode byte 0xe1 in position" because of a sharp comment.

The problem wouldn’t be serious if I didn’t need to show comments and descriptions in the fields that will be filled by users.

I’ve tried to include it in the code: {% include "base/js.html, encoding='latin-1', engine='python'" %}

but the error persists and all references I found on this site or in others only tell how to read a file in csv format (which is not my case).

I humbly ask for your help in solving this problem that is impaling me.

Thanks so much for all the help I get.

  • Try putting # encoding: utf-8 at the beginning of the file that has these comments

  • Good morning, Miguel and thank you for your suggestion. I entered the line and it did not work. The error persists. Currently the CSS.HTML file has the following content: {% load Static %} # encoding: utf-8 <! -- Reader of the base.html style page --> <link rel="stylesheet" href="{% Static 'css/main.css' %}" <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">#Xa;<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat">

  • Take a look here: https://wiki.python.org/moin/UnicodeDecodeError

1 answer

3


Your template file is saved with "latin-1" encoding - Windows native, not 'utf-8' universal encoding, where it is more practical to write software projects.

The accent encoding of the files depends on the configuration of the program you are using to edit the files. (the windows "Notepad" does not even allow changing this encoding).

Explore the encoding options of the tool you are using to edit the project, open your template files, switch to "utf-8" and save again.

You can probably tell Django to wait for the files in latin1 instead of utf-8, passing parameters, or even settings - but the headache is not worth it: you better have the whole project in utf-9 that is already expected by default.

  • I have actually used Visual Studio to create my files. After opening them with Notepad++ and changing the encoding, it worked! Thank you very much!!!

  • Just adding: I could say that the encoding is "latin-1" because I know it is the default Windows encoding in Portuguese, and, after years dealing with coding issues, I know that "0xe1" is a typical value of a Portuguese accent in this encoding (I don’t know which one) ) - via d rule does not have a "guess" form in which encoding a file is, except by trial and error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.