设置可以由网络上其他设备访问的Django开发服务器 [英] Setting up a Django development server that can be accessed by other devices on my network

查看:46
本文介绍了设置可以由网络上其他设备访问的Django开发服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置一个Django开发服务器,我的计算机和智能手机都可以通过wifi在我的网络上访问它.

I want to set up a Django development server that both my computers and smart phones can access whilst on my network via wifi.

我已经设置了我的计算机可以在 http://127.0.0.1:8000上访问的开发服务器./.但是,我的其他设备不能.

I've already set up a development server that my computer can access on http://127.0.0.1:8000/. However, my other devices can't.

Django文档说:

The Django documentation says:

请注意,无法从网络上的其他计算机访问默认IP地址127.0.0.1.要使开发服务器对网络上的其他计算机可见,请使用其自己的IP地址(例如192.168.2.1)或0.0.0.0或::(启用了IPv6)."

"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)."

我找到了我的公共IP地址",并尝试通过以下方式使用它:python manage.py runserver xx.xx.xxx.x(这是我的公共IP地址),但出现命令错误:'xx.xx.xxx.x"不是有效的端口号或地址:端口对."

I've found my "public IP address" and tried to use this by: python manage.py runserver xx.xx.xxx.x (where this is my public ip address) but i get a "Command error: 'xx.xx.xxx.x' is not a valid port number or address:port pair."

然后我尝试使用IP地址后面的:8000,但出现错误错误:无法将该IP地址分配给它".

I then tried the same with :8000 after the IP address, but got an error "Error: That IP address can't be assigned to".

然后使用python manage.py runserver 0.0.0.0:8000.命令行报告在...处启动开发服务器",但是当我尝试" http://0.0.0.0时:8000/"在Chrome上,我收到无法访问此网站的错误".

Then python manage.py runserver 0.0.0.0:8000. The command line reports "Starting development server at ...", but when i try "http://0.0.0.0:8000/" on Chrome, i get a "This site can't be reached error".

与Windows防火墙设置有关吗?请你有人可以帮我吗?谢谢!

Is it something to do with my windows firewall settings? Please can you someone help me? Thanks!

推荐答案

0.0.0.0不是真实地址,它只是一个占位符,它表示服务器未绑定到特定IP.

0.0.0.0 is not a real address, it's a placeholder that just says that the server is not bound to a specific IP.

如果您在127.0.0.1上运行,它将仅回答寻址到127.0.0.1的查询,因此仅适用于本地主机.

If you run on 127.0.0.1, it will only answer to queries that where addressed to 127.0.0.1, so localhost only.

使用您的专用地址(最常用的是192.168.0.x),它只会回答对该地址的查询(因此,打开127.0.0.1不能正常工作,但有时取决于实现方式)

Using your private address (192.168.0.x most often), it will only answer to queries to this address (so opening with the 127.0.0.1 should not work, but sometime does depending on the implementation)

因此,如果您使用0.0.0.0,它将回答任何问题.

So, if you use 0.0.0.0, it will answer to anything.

tl; dr:使用0.0.0.0,然后使用:

tl;dr : use 0.0.0.0 and connect using :

  • 此计算机上的127.0.0.1

  • 127.0.0.1 from this computer

您局域网中其他计算机的计算机专用IP地址

your computer's private ip address for other computers inside your lan

您的局域网外计算机的公共IP.请注意,这将需要在路由器上进行其他配置

you public IP for computers outside your lan. Note that this will require additional configuration on your router

这篇关于设置可以由网络上其他设备访问的Django开发服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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