简体   繁体   中英

How can I provide the Rest Framework API to intranet machine?

I use the rest framework write APIs, and when I runserver the website I can access the APIs in the development machine(the intranet ip is 10.10.10.111 ):

在此处输入图片说明

But how can I access the API in other computer which is in the 10.10.10.0/24 intranet?

If can, this will become more convenient for our team to debugging.

To make your development server view-able to other machines on the network, use its own IP address (eg 10.10.10.111) or 0.0.0.0.

See the examples for running django projects on different ports and ip address.

The command will be:

django-admin runserver 0.0.0.0:<port>

or

python manage.py runserver 0.0.0.0:<port>

You can then visit the site in 10.10.10.111:<port> or <your.machine.ip.address:port> from same network.

What @salman said plus: This is most likely the host computers firewall blocking the packets. Depending on your OS try to selectively open this port.

Edit

Most likely the firewall on the host (*) machine will block the traffic. Also ask your admin if a firewall in the network blocks the port.

*) host meaning „the machine running the server

Runserver in Django project:

python manage.py runserver 0.0.0.0:<port>

stop the firewall in your develop OS, such as the CentOS7:

systemctl stop firewalld.service

then add the ALLOW_HOST in your project settings.py, because your computer are connected use inner network, you can allow all:

ALLOWED_HOSTS = ['*']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM