django 运行 来自连接到另一个网络的另一台计算机的本地主机
django run localhost from another computer connected to another network
我正在 运行在本地主机上安装我的 django 项目,它工作正常..
出于测试目的,我想从连接在同一网络中的另一台计算机 运行 我的本地主机。
我已经完成了python manage.py runserver 'my ip address'
这也很好..有什么方法可以让我从连接到另一个网络的另一台计算机访问我的本地主机?
就像我连接到 A 网络,运行宁我的本地主机和我的朋友连接到 B 网络。假设他想访问我的本地主机并查看我的项目 运行ning 那么是否可以从连接到另一个项目的另一台计算机访问一台计算机的本地主机?
可以。只是 运行
中的 django 运行 服务器
python manage.py runserver 0.0.0.0:8000
现在您可以使用 youripaddress:8000
访问您的应用
来自 Django ...
Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. To make your development server viewable to other machines on the network, use its own IP address (e.g. 192.168.2.1) or 0.0.0.0 or :: (with IPv6 enabled).
You can provide an IPv6 address surrounded by brackets (e.g. [200a::1]:8000). This will automatically enable IPv6 support.
已更新:
为了匹配问题标题的答案。您需要将路由器配置为将端口 80 转发到您的应用程序地址
运行 具有本地主机或您的系统 IP 的服务器,如下所示
python manage.py runserver 192.168.6.7:8000
python manage.py runserver 0.0.0.0:8000
python manage.py runserver 127.0.0.1:8000
在settings.py中添加主机以从网络中的其他系统访问。
ALLOWED_HOSTS = ['127.0.0.1', 'localhost','192.168.6.7']
如果您在 Django 项目中工作 DEBUG=True
mod,除此之外您不需要任何其他东西(我假设您没有使用端口 80,它需要 root 访问权限)。
您必须使用 0.0.0.0
作为主机 IP,这是一个简单的解决方案。命令是:
python manage.py runserver 0.0.0.0:8000
。就是这样。
我正在 运行在本地主机上安装我的 django 项目,它工作正常.. 出于测试目的,我想从连接在同一网络中的另一台计算机 运行 我的本地主机。
我已经完成了python manage.py runserver 'my ip address'
这也很好..有什么方法可以让我从连接到另一个网络的另一台计算机访问我的本地主机?
就像我连接到 A 网络,运行宁我的本地主机和我的朋友连接到 B 网络。假设他想访问我的本地主机并查看我的项目 运行ning 那么是否可以从连接到另一个项目的另一台计算机访问一台计算机的本地主机?
可以。只是 运行
中的 django 运行 服务器python manage.py runserver 0.0.0.0:8000
现在您可以使用 youripaddress:8000
来自 Django ...
Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. To make your development server viewable to other machines on the network, use its own IP address (e.g. 192.168.2.1) or 0.0.0.0 or :: (with IPv6 enabled).
You can provide an IPv6 address surrounded by brackets (e.g. [200a::1]:8000). This will automatically enable IPv6 support.
已更新:
为了匹配问题标题的答案。您需要将路由器配置为将端口 80 转发到您的应用程序地址
运行 具有本地主机或您的系统 IP 的服务器,如下所示
python manage.py runserver 192.168.6.7:8000
python manage.py runserver 0.0.0.0:8000
python manage.py runserver 127.0.0.1:8000
在settings.py中添加主机以从网络中的其他系统访问。
ALLOWED_HOSTS = ['127.0.0.1', 'localhost','192.168.6.7']
如果您在 Django 项目中工作 DEBUG=True
mod,除此之外您不需要任何其他东西(我假设您没有使用端口 80,它需要 root 访问权限)。
您必须使用 0.0.0.0
作为主机 IP,这是一个简单的解决方案。命令是:
python manage.py runserver 0.0.0.0:8000
。就是这样。