Django的manage.py runserver命令无法运行

7

我尝试使用命令启动服务器时遇到了问题

python manage.py runserver 0.0.0.0:8000

它正在显示

C:\abc>python manage.py runserver 0.0.0.0:8000
Validating models...

0 errors found
Django version 1.4.9, using settings 'abc.settings'
Development server is running at http://0.0.0.0:8000/
Quit the server with CTRL-BREAK.

但是无法通过 http://127.0.0.1:8000 在浏览器中访问。

它显示的是:

Unable to connect

Firefox can't establish a connection to the server at 127.0.0.1:8000.

The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer's network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.

但是当我尝试相同的操作时,
python manage.py runserver 

应用程序运行正常,我可以访问 http://127.0.0.1:8000

可能的问题是什么?


奇怪的是,当我尝试python manage.py runserver 0.0.0.0:8080时它可以工作,但是当我尝试python manage.py runserver 0.0.0.0:8000时却不行。端口8000可能存在问题,我不确定是否被之前默认分配8000端口的python manage.py runserver占用了。我认为这不应该发生。 - curiousguy
如果是这种情况 @init3,那么为什么 python manage.py runserver 运行良好,它正在端口 8000 上运行,http:\\127.0.0.1:8000 - curiousguy
将8000绑定到0.0.0.0(例如192.168.1.1的别名)无效。将8000绑定到127.0.0.1(无别名)有效。将8080绑定到0.0.0.0(例如192.168.1.1)有效-未使用。这就是原因:) 检查netstat -tulpn | grep 8000以查看外部IP是否仍在使用端口8000。 - Thomas Schwärzl
1
是的,你说得对@init3尝试了这个`C:\ Users \ 15809> netstat -an活动连接  Proto本地地址外国地址状态   TCP 0.0.0.0:4105 0.0.0.0:0 LISTENING   TCP 0.0.0.0:4728 0.0.0.0:0 LISTENING   TCP 0.0.0.0:7163 0.0.0.0:0 LISTENING   TCP 0.0.0.0:8000 0.0.0.0:0 LISTENING   TCP 0.0.0.0:8000 0.0.0.0:0 LISTENING   TCP 0.0.0.0:47001 0.0.0.0:0 LISTENING` - curiousguy
发布“官方答案”-也许我会得到一点点赞? :) - Thomas Schwärzl
显示剩余4条评论
1个回答

9

看起来你的外部IP正在使用端口8000,请查看是否有进程正在运行并终止它。

你可以使用netstat -a检查打开的端口。在Debian中,你可以使用netstat -tulpn | grep 8000获取PID。最后一行应该显示类似于1234/python的内容。现在使用kill 1234结束它。

或者你可以重新启动系统 ;-)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接