Use the API outside the server


I created the APIs using DRF and they are uploaded on cloud Virtual machine. I want to use that these API outside the sever using public IP. But the issue is whenever I assign the public IP it shows me below error. Is there any other way to use this API outside the server?


I think you are trying to asing the public ip to the web server, but you can’t, you should use as the ip in the command.

Hello Daniel,

Thank you so much for the reply.

I also used python runserver in cmd so that whatever the ip that are mentioned in the ALLOWED_HOSTS will work on browser but that is also not working. The private ip/ localhost is working fine but with public ip it is not working.
Note : I had also mentioned public ip, private ip and localhost in ALLOWED_HOSTS.

Please be more specific. What is the behavior you are seeing?

Check to ensure that there’s no firewall blocking access to that port.

Also, if this is something you’re going to leave up and running, you do not want to use runserver as the persistent means of running your application.

From the docs for runserver:

DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests.

Also start with: How to deploy Django.

Since this is a DRF-based project, some of the steps may not apply, but you should still be familiar with the process.