The source file with unicode characters makes Django throw a SyntaxError exception

A UTF-8 encoded file has the è character (e with an impact grave) embedded in Python comment delimiters. Django complains about this character and will not display the page. How can i solve this?

+6
source share
2 answers

SyntaxError Django is already raising what you are in the right direction.

It is always useful to read exceptions. In your case, he would say something in the lines

The non-ASCII character '\ xc3' in the file /home/zakx/../views.py on line 84, but no encoding is declared; See http://www.python.org/peps/pep-0263.html (views.py, line 84) for more information.

If you then read PEP-0263 , you might find out that there are some ways to tell Python (and your editor!) That encode your files. Typically, you will want to use UTF-8 encoding whenever possible. Therefore, writing one of the following lines to the first line (or, secondly, if you use shebang), Python will use UTF-8 for this file.

 # coding=utf8 # -*- coding: utf8 -*- # vim: set fileencoding=utf8 : 
+18
source

Have you tried adding the coding header to the file? In the first line, possibly after the shebang line, add

 # -*- coding: utf-8 -*- 
+3
source

Source: https://habr.com/ru/post/893478/


All Articles