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:
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). 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.
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. I hope it helps you. 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',
]
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.
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.