django从连接到任何网络的任何计算机访问本地主机 [英] django accessing localhost from any machine connected to any network

查看:139
本文介绍了django从连接到任何网络的任何计算机访问本地主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在localhost:8000上运行的django项目,并且工作正常. 现在,我希望它可以从连接到其他网络的任何计算机进行访问.

I have a django project that I am running on localhost:8000 and that works fine. Now I want it to access from any machine that is connnected to other network.

做一些谷歌,我发现我可以通过设置路由器的端口转发来做到这一点. 我有一个tplink路由器,并且进行了以下设置:

Doing some google I found that I can do it by setting port forwarding from my router. I have a tplink router and I did the following setting:

Service Port:27015
IP Address: my_ip_address   # obtained by ifconfig
Protocol: All
Status: Enabled

现在我用python manage.py my_ip_address:27015

但是当我在连接到另一个网络的另一台计算机上使用my_ip_address:27015的url运行时,我无法查看我的站点/页面

But when I run with my_ip_address:27015 in url from another machine connected to another network I cannot view my site/page

有人可以帮助我如何访问我的本地主机吗?

Can anyone help me how to access my localhost outside the globe?

推荐答案

您无法在外部访问localhost表单;本地主机服务器将仅在本地主机设备"上响应.

You can not access localhost form outside; localhost servers will only respond on the localhost "device".

您需要启动服务器(在本例中为django),并将其绑定到您的本地地址(192.168或10,等等).

you need to start the server, in this case django, and have it bind to your local address (192.168, or 10., etc).

python manage.py runserver 0.0.0.0:8000

将其绑定到计算机上所有可用的IP地址.

will have it bind to all available IP addresses on your machine.

然后,您可以将路由器上的端口转发到本地计算机(在本地计算机上为该端口禁用防火墙)

Then you can port forward on your router to your local machine (disable any firewall for that port on your local machine)

这篇关于django从连接到任何网络的任何计算机访问本地主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆