简体   繁体   English

如何通过 ip 地址使用另一台设备连接到我的 Django 本地网络服务器?

[英]How do I connect to my Django local webserver using another device through ip address?

I created a dummy website using Django, python, HTML, CSS, and JavaScript recently. I created a dummy website using Django, python, HTML, CSS, and JavaScript recently. After completing it I tested the website by starting the server.完成后,我通过启动服务器来测试网站。

python3 manage.py runserver

I was able to open the website in a browser in the local machine using the link 127.0.0.1:8000/我能够使用链接127.0.0.1:8000/在本地计算机的浏览器中打开该网站

Now, I want to connect to this server using my android device.现在,我想使用我的 android 设备连接到该服务器。

As my first step I started a hotspot on my android which I've connected my pc by wifi in order to bring the client and server in the same network.作为我的第一步,我在我的 android 上启动了一个热点,我通过 wifi 连接了我的电脑,以便将客户端和服务器置于同一个网络中。

Then I figured out the local IP address of my PC and I've switched off the firewall on my PC.然后我找出了我电脑的本地 IP 地址,我已经关闭了我电脑上的防火墙。

After doing that I ran the Django runserver command with this address,之后我用这个地址运行了 Django runserver 命令,

python3 manage.py runserver 0.0.0.0:8000

And just like before I am able to use the website without a problem in my local machine/PC.就像在我能够在本地机器/PC 上毫无问题地使用该网站之前一样。 However, when I tried to connect to this with my mobile using the link,但是,当我尝试使用该链接与我的手机连接时,

192.168.45.220:8000 192.168.45.220:8000

Where 192.168.45.220 is the IP address of the PC which I'm running as the current local server.其中192.168.45.220是我作为当前本地服务器运行的 PC 的 IP 地址。 I get a error message as我收到一条错误消息

The site can't be reached 127.0.0.1 refused to connect ERR_CONNECTION_REFUSED站点无法访问 127.0.0.1 拒绝连接 ERR_CONNECTION_REFUSED

I don't understand what I am doing wrong.我不明白我做错了什么。 Can someone let me know what I could do to fix this?有人可以让我知道我能做些什么来解决这个问题吗? Thanks.谢谢。

You need to use the IP address of your computer in your local network (assuming your mobile device is on the same network as your desktop).您需要在本地网络中使用您的计算机的 IP 地址(假设您的移动设备与您的台式机在同一网络上)。 On Linux and Mac you can check your IP with ifconfig or using ipconfig on Windows.在 Linux 和 Mac 上,您可以使用 ifconfig 或在 Windows 上使用 ipconfig 检查您的 IP。 localhost always refers to the current machine, ie localhost on your desktop points to your desktop and on your mobile device it points to your mobile device. localhost 总是指当前机器,即桌面上的 localhost 指向您的桌面,而在您的移动设备上它指向您的移动设备。 That's why you can't access it - the app runs on your desktop not mobile.这就是您无法访问它的原因 - 该应用程序在您的桌面而不是移动设备上运行。

Once you know the IP address of your computer you need to replace localhost with it.一旦您知道计算机的 IP 地址,您需要用它替换 localhost。 In my case the IP is 192.168.1.10 so I use the following address to access my app:在我的情况下,IP 是 192.168.1.10 所以我使用以下地址访问我的应用程序:

http://192.168.1.10:8000/ http://192.168.1.10:8000/

1.Type in cmd (windows): ipconfig 1.输入cmd(windows):ipconfig
2.Look for IP address IPV4: 2.寻找IP地址IPV4: 在此处输入图像描述
3. Type in URL search bar of your browser (example): 192.168.1.4:3000 3000 is the port number that your react app is running on: 3. 在浏览器的搜索栏中输入 URL(示例): 192.168.1.4:3000 3000 是您的 react 应用程序运行的端口号: 在此处输入图像描述 4.Make sure that your mobile browser (Chrome is preferred) is on the latest update, my react app didn't load up for me because chrome wasn't updated. 4.确保您的移动浏览器(首选 Chrome)处于最新更新状态,我的 react 应用程序没有为我加载,因为 chrome 没有更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎样才能找到我的 ip 地址与 python 不是本地 ip? - how can i find my ip address with python not local ip? 我如何让django-debug-toolbar只显示在python托管的我的IP地址上的任何地方? - How do I get django-debug-toolbar to only display on my ip address hosted on python anywhere? 如何在 Django 中获取用户 IP 地址? - How do I get user IP address in Django? 如何确定设备使用的 IP 范围? - How do I determine what ip range a device is using? 如何通过 Dart/Flutter 中的主机名获取本地连接设备的 IP 地址? - How do I get the IP address of a locally connected device by its hostname in Dart/Flutter? 如何在 Windows 10 上获取 ORACLE 11 g DATABASE 的 IP 地址以远程连接到它? - How do i get the IP address of ORACLE 11 g DATABASE on windows 10 to remotely connect to it? 如何为我的 python 脚本创建本地网络服务器? - How can I create an local webserver for my python scripts? 如何使用CherryPy配置IP地址? - How do I configure the ip address with CherryPy? 如何获取使用django for python访问我的网站的IP地址 - how to get the ip address who are accessing my website using django for python 如何使python OSC Server监听自己的IP地址? - How do I make my python OSC Server listen to my own IP address?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM