尝试在我的项目上打开管理页面时出错了。排在urls.py的麻烦
url(r'^letter/([a-zA-Z0-9µ])/$', common.views.letters),
错误:
UnicodeDecodeError at /admin/
'ascii' codec can't decode byte 0xc2 in position 19: ordinal not in range(128)
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.6
Exception Type: UnicodeDecodeError
Exception Value:
'ascii' codec can't decode byte 0xc2 in position 19: ordinal not in range(128)
Exception Location: C:\Python27\lib\site-packages\django\core\urlresolvers.py in _populate, line 264
Python Executable: C:\Python27\python.exe
Python Version: 2.7.3
除管理页面以外的项目工作正常。我理解“μ”中的问题。但是如何让它发挥作用?
urls.py的第一行:
# -*- coding: utf-8 -*-
答案 0 :(得分:1)
指定要像这样明确使用的编码
# -*- coding: latin-1 -*-
print (r'^letter/([a-zA-Z0-9µ])/$')
<强>输出强>
^letter/([a-zA-Z0-9µ])/$
答案 1 :(得分:0)
尝试添加
# -*- coding: utf-8 -*-
作为你的第一行。