运行Django应用时出错
当我在pycharm或者命令行中运行django项目时,出现了这个错误。我该怎么办呢?
"C:\Program Files (x86)\JetBrains\PyCharm 3.4.1\bin\runnerw.exe" C:\Python34\python.exe C:/Users/admin/PycharmProjects/untitled/manage.py runserver 8000 正在验证模型...
0 errors found
August 15, 2014 - 13:58:27
Django version 1.6.5, using settings 'untitled.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x022A32B8>
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django\utils\autoreload.py", line 93, in wrapper
fn(*args, **kwargs)
File "C:\Python34\lib\site-packages\django\core\management\commands\runserver.py", line 127, in inner_run
ipv6=self.use_ipv6, threading=threading)
File "C:\Python34\lib\site-packages\django\core\servers\basehttp.py", line 167, in run
httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
File "C:\Python34\lib\site-packages\django\core\servers\basehttp.py", line 109, in __init__
super(WSGIServer, self).__init__(*args, **kwargs)
File "C:\Python34\lib\socketserver.py", line 429, in __init__
self.server_bind()
File "C:\Python34\lib\site-packages\django\core\servers\basehttp.py", line 113, in server_bind
super(WSGIServer, self).server_bind()
File "C:\Python34\lib\wsgiref\simple_server.py", line 50, in server_bind
HTTPServer.server_bind(self)
File "C:\Python34\lib\http\server.py", line 135, in server_bind
self.server_name = socket.getfqdn(host)
File "C:\Python34\lib\socket.py", line 460, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 6: invalid continuation byte
3 个回答
0
试着检查一下主机名。可能你的主机名里包含了一些非ASCII字符。看起来你是在使用Windows 7操作系统。
0
1) 检查你的 settings.py、manage.py、wsgi.py 等文件,看看里面有没有非ASCII字符。
2) 如果找到了,就在文件开头添加
# -*- coding: utf-8 -*-
这段代码。
3) 另外,对于包含非ASCII字符的字符串,要在字符串前面加个 u。
比如:u"这些字符不是unicode : üşiğç"
///适用于 python 2.x