【发布时间】:2018-06-27 16:40:19
【问题描述】:
我试图为我的MEDIA_ROOT 赋予一个包含带重音符号的单词的值,但 django 不接受它。
我尝试了 unicode(utf-8) 并对其进行编码,但没有得到肯定的结果
我得到的错误是:SyntaxError: Non-ASCII character '\xc3' in file
我该怎么做才能使设置接受重音符号(ó,á,é,í,ú)
SyntaxError: Non-ASCII character '\xc3' in file C:\Users\Meccha\Documents\django\project\settings.py on line 160, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
在第 160 行我有:MEDIA_ROOT = os.path.join(u'D:', u'INVESTIGACIÓN._P')
【问题讨论】:
-
你在运行 Python-2.x 吗?
-
是的,python 2.7 和 django 1.11
-
那么你需要在它前面加上一个
u,所以u'foo/bar/qux'insteaf of'foo/bar/qux'。 -
我得到同样的错误
SyntaxError: Non-ASCII character '\xc3' in file settings.py but no encoding declared -
在顶部添加
# -*- coding: utf-8 -*-