Django django allow external access to the LAN configuration

Reprinted from: https://www.cnblogs.com/areyouready/p/9029075.html   https://jackyu.cn/tech/access-django-website-in-intranet/

 

django allow external access

The default method to start django

python manage.py runserver
Then start the service can only access this machine, because the service is only available to native (127.0.0.1:8000), so other machines can not access the LAN.
 
If you want other computers on the network can access django service, you need to change the command to start django
python manage.py runserver 0.0.0.0:8000
To
 
You need to specify the time of the visit is http visit the following format:
http://192.168.75.129:8000
 

The first point: you need in a document in accordance with the following settings setting.py:
allowed_hosts = [ "*"]

He said the limited access, for example, I fill a ip, 192.168.1.1; then I will only allow the ip access to my site; also may not fully qualified, such as 192.168.1. *; Can also be a domain name "sb .com ", it would match the suffix" sb.com "domain name;

Second, and very importantly, be sure to turn off your firewall;

The third point, your server-start up, must be in 0.0.0.0:8000

In this way, your colleagues can through your computer's ip address and the corresponding routing, to access your project a
---------------------
Author: Butter cat
Source : CSDN
original: https: //blog.csdn.net/miantian180/article/details/79556848
copyright: This article is a blogger original article, reproduced, please attach Bowen link!

 
 

1 Turn off the firewall

service iptables stop  
  • 1

2 Set django

开开启django时,使用0.0.0.0:xxxx,作为ip和端口例如: python manage.py runserver 0.0.0.0:9000 然后在settings里修改ALLOWED_HOSTS = [], 改为ALLOWED_HOSTS = ['*',],注意不要漏掉“,”。 其他机器就可以通过这台机器的ip和端口号访问django了。 例如:http://192.168.14.40:9000/index.html
 

Django LAN access

The default method to start django

python manage.py runserver
Then start the service can only access this machine, because the service is only available to native (127.0.0.1:8000), so other machines can not access the LAN.
 
If you want other computers on the network can access django service, you need to change the command to start django
python manage.py runserver 0.0.0.0:8000
To
 
You need to specify the time of the visit is http visit the following format:
http://192.168.75.129:8000
 

第一点:需要在你的setting.py文件中将按照如下设置:
ALLOWED_HOSTS = ["*"]

他表示所限定的访问,比如我填写一个ip,192.168.1.1;那么我就只允许该ip对我的网站访问;也可以是不完全限定,如192.168.1.*;还可以是域名“sb.com”,那么它将匹配后缀为"sb.com"的域名;

第二点,也是很重要的一点,一定要关闭你的防火墙;

第三点,将你的服务器启动器起来,必须是在0.0.0.0:8000

这样,你的同事就可以通过你电脑的ip地址以及相应的路由,来访问你的项目了
---------------------
作者:黄油猫
来源:CSDN
原文:https://blog.csdn.net/miantian180/article/details/79556848
版权声明:本文为博主原创文章,转载请附上博文链接!

 
 

1关闭防火墙

service iptables stop  
  • 1

2设置django

开开启django时,使用0.0.0.0:xxxx,作为ip和端口例如: python manage.py runserver 0.0.0.0:9000 然后在settings里修改ALLOWED_HOSTS = [], 改为ALLOWED_HOSTS = ['*',],注意不要漏掉“,”。 其他机器就可以通过这台机器的ip和端口号访问django了。 例如:http://192.168.14.40:9000/index.html
 

Django 局域网内访问

Guess you like

Origin www.cnblogs.com/hanwenlin/p/11275711.html