Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 从外部访问本地主机?_Django_Localhost_Static Ip Address - Fatal编程技术网

Django 从外部访问本地主机?

Django 从外部访问本地主机?,django,localhost,static-ip-address,Django,Localhost,Static Ip Address,这可能是一个非常基本的问题。我使用SSH连接到虚拟Ubuntu服务器,并启动在本地主机上运行的django Web服务器: Downloading/unpacking django Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded Installing collected packages: django Successfully installed django Cleaning up... Pe

这可能是一个非常基本的问题。我使用SSH连接到虚拟Ubuntu服务器,并启动在本地主机上运行的django Web服务器:

Downloading/unpacking django
  Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded
Installing collected packages: django
Successfully installed django
Cleaning up...
Performing system checks...

System check identified no issues (0 silenced).

You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.

April 13, 2016 - 14:16:19
Django version 1.9.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Ubuntu服务器有一个静态IP[x.xxx.xxx.xxx],因此,从另一个网络上的另一台机器上,我尝试使用该静态IP地址在浏览器中访问上述网站:

x.xxx.xxx.xxx:8000
但我得到:

This site can’t be reached

x.xxx.xxx.xxx refused to connect.
ERR_CONNECTION_REFUSED
因此,我假设我无法访问这样的网站,即使主机有外部/静态IP地址,该网站也只能在主机上使用

编辑:

答案也在于:


您需要在
0.0.0.0:8000
上运行web服务器,然后在外部使用ip或主机名进行访问。使用
0.0.0.0
意味着django服务将侦听所有配置的网络接口

查看有关0.0.0.0的详细信息


服务器上的另一个故障可能会有帮助。

你不是说0.0.0.0:8000吗?看,是的,对不起,我打错了。
python manage.py runserver 0.0.0.0:8000