Python 使 Django 服务器在 LAN 中可访问
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22144189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
making django server accessible in LAN
提问by sumit
I have installed django server and it can be accessible as below
我已经安装了 django 服务器,它可以如下访问
http://localhost:8000/get-sms/
http://127.0.0.1:8000/get-sms/
suppose My ip is x.x.x.x .
假设我的 ip 是 xxxx 。
From another PC under same network when I do
当我这样做时,从同一网络下的另一台PC
my-ip:8000/get-sms/it is not working.
my-ip:8000/get-sms/它不工作。
I can easily ping my IP with that computer.
我可以很容易地用那台电脑ping我的IP。
Moreover on my port 81 i have apache, which is eaily accessible like below
此外,在我的端口 81 上,我有 apache,可以像下面一样轻松访问
http:///my-ip:81
what can be the issue? Do I need something extra in django
可能是什么问题?我需要在 Django 中添加一些额外的东西吗
采纳答案by Depado
Running the Django Development Server
This is what you're looking for. To help you further, here is what you should do:
运行 Django 开发服务器
这就是你要找的。为了进一步帮助您,您应该执行以下操作:
python manage.py runserver 0.0.0.0:8000
By the way, this may be a duplicate of thisquestion.
顺便说一句,这可能是这个问题的重复。
Here is what the documentation says:
以下是文档中的内容:
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.
请注意,网络上的其他计算机无法访问默认 IP 地址 127.0.0.1。要使您的开发服务器对网络上的其他机器可见,请使用其自己的 IP 地址(例如 192.168.2.1)或 0.0.0.0。
回答by Venkatesh Bachu
you can use https://forwardhq.com/or https://ngrok.com/, these tools will expose your local web server to the internet/public.
您可以使用https://forwardhq.com/或https://ngrok.com/,这些工具会将您的本地网络服务器暴露给互联网/公共。
回答by Achala Dissanayake
To add @Depado 's answer you may need to add your LAN IP address to ALLOWED_HOSTSin the settings.pyalong with localhost. it would look like,
要添加@Depado的答案,你可能需要你的局域网IP地址添加到ALLOWED_HOSTS在 settings.py沿 localhost。它看起来像,
ALLOWED_HOSTS = ["localhost", "192.168.8.160"]

