我正在关注Django文档的第一个教程来运行我的开发服务器,但是目前尝试访问http://127.0.0.1:8000中的服务器它无法连接。浏览器只是说它无法连接到服务器。这是我在输入命令python manage.py runserver
时输出控制台的信息:
System check identified no issues (0 silenced).
August 03, 2017 - 14:31:04
Django version 1.11.4, using settings 'mysite.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 0x0000000003E14730>
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site-packages\django\utils\autoreload.py",
line 228, in wrapper
fn(*args, **kwargs)
File "C:\Program Files\Python36\lib\site-packages\django\core\management\comma
nds\runserver.py", line 149, in inner_run
ipv6=self.use_ipv6, threading=threading, server_cls=self.server_cls)
File "C:\Program Files\Python36\lib\site-packages\django\core\servers\basehttp
.py", line 164, in run
httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
File "C:\Program Files\Python36\lib\site-packages\django\core\servers\basehttp
.py", line 74, in __init__
super(WSGIServer, self).__init__(*args, **kwargs)
File "C:\Program Files\Python36\lib\socketserver.py", line 453, in __init__
self.server_bind()
File "C:\Program Files\Python36\lib\wsgiref\simple_server.py", line 50, in ser
ver_bind
HTTPServer.server_bind(self)
File "C:\Program Files\Python36\lib\http\server.py", line 138, in server_bind
self.server_name = socket.getfqdn(host)
File "C:\Program Files\Python36\lib\socket.py", line 673, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf3 in position 3: invalid
continuation byte
我在Windows 7上使用python 3.6.1和django 1.11.4。
编辑:我忘了提到我正在使用启动项目(使用命令django-admin startproject mysite
生成)而没有任何编辑。
答案 0 :(得分:1)
Your hostname must have some weird characters, try to change it. Or you can try to force Django to use the host and port you want:
python manange.py runserver 127.0.0.1:8000
Hope that can help you!
答案 1 :(得分:0)
您应该在相应的文件夹中运行python manage.py runserver命令。例如,如果您的manage.py是在myproject文件夹中创建的,则必须在命令提示符下的该文件夹中运行以上命令。 (venv)C:\ Users \ sasi \ Desktop \ Development \ myproject \ myproject> python manage.py runserver
希望这对您有帮助