ITPub博客

首页 > 应用开发 > > django执行runserver后端口不通的解决方法

django执行runserver后端口不通的解决方法

作者:tzhang911 时间:2019-09-05 13:41:05 0 删除 编辑

在执行Pythonmanage.py runserver后发现如下现象(docker中也会出现):

1,服务器上执行telnet localhost 8000可以连上

2,其他主机telnet服务器发现该端口无法连上  服务器的页面也打不开

解决方法:

执行python manage.pyrunserver时 后面加上0.0.0.0:8000

原因:

默认情况下Django runserver命令只是绑定本地主机。

By default, therunservercommand starts the development server on the internal IP at port 8000.

If you want to change the server’s port, pass it as a command-line argument. For instance, this command starts the server on port 8080:

$python manage.py runserver 8000

If you want to change the server’s IP, pass it along with the port. So to listen on all public IPs (useful if you want to show off your work on other computers), use:

$python manage.py runserver 0.0.0.0:8000

ps.还是google靠谱,百度推荐的知道的答案太坑了

另外,之后如果用浏览器测试默认页面出现ALLOW_HOSTS的设置提示,可在进入一层目录修改settings.py文件中的

ALLOW_HOSTS = ['*']

即可

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1926/viewspace-3152925/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-16

  • 博文量
    100
  • 访问量
    753