[Vuejs]-How to handle POST net::ERR_CONNECTION_REFUSED error in Axios Vue.js django

0👍

I encountered the same problem. Here’s how I solved it:

  1. Install django-cors-headers by executing the following in your terminal:
pip install django-cors-headers
  1. In your settings.py file, insert the following:
MIDDLEWARE = [
   ...,
   "corsheaders.middleware.CorsMiddleware",
   "django.middleware.common.CommonMiddleware",
]

CORS_ORIGIN_WHITELIST = [
   'http://localhost:8000',
   'http://127.0.0.1:8000/'
]

Then that should do it. If not, then here’s step 3):

  1. In your settings.py file:
INSTALLED_APPS = [
   ...,
   "corsheader"
   ...,
]

From the django-cors-headers 3.14.0 package documentation:

This [django-cors-headers] allows in-browser requests to your Django application from other origins.

You can access the package and read more about it by following this link: https://pypi.org/project/django-cors-headers/

I hope this helped.

Leave a comment