0

I am trying to test a Django app by using other devices in my local network. I am using Angular as my client.
So far, I am able to run my Angular app on other devices. However, whenever I try to make any sort of request, I get back a response specifying: net::ERR_CONNECTION_REFUSED

I am able to properly run both the client app and Django REST server in my local machine but it's not the case when it comes to other devices.

Based on some of the already posted solutions, I have done :

  1. Binding Django server to IP : 0.0.0.0:8000 by running python .\manage.py runsslserver --certificate .\ssl\server.crt --key .\ssl\server.key 0.0.0.0:8000 (I am using SSL for both client and server).
  2. Setting ALLOWED_HOSTS to ['*'] in settings.py.

But the error is still persistent. All the devices (including my local machine) which I am using is Windows if that's important.


Can someone help me in fixing this issue? Or are there any other way to run the API server?
noobron
  • 3
  • 3

2 Answers2

0

Hi i think this is a problem with cors. You can try installing django-cors-headers. Here is a small guide on how to do that. Remember to add in CORS_ALLOWED_ORIGINS the host and port on which angular is running. For example if angular is running on port 3000:

CORS_ALLOWED_ORIGINS = [
    'http://localhost:3000',
]
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Thank you for the reply. Apparently, I have set ```CORS_ALLOW_ALL_ORIGINS = True``` in settings.py. So adding ```CORS_ALLOWED_ORIGINS = [ 'http://localhost:3000' ]``` won't have any effect. I am not getting any CORS errors also. – noobron Jan 10 '22 at 12:42
0

Got it working.
It was just a small bug in my angular app configuration for accessing API URL.
Just had to update the IP address (or the URI) in which the API server was running.

noobron
  • 3
  • 3