title: How do I fix "POST http://127.0.0.1:8000/admin/auth/user/ net::ERR_CONNECTION_REFUSED" error in Vue project?
body: <p>I'm making a Vue project and, when making an <code>axios.post</code> call in my vue file, I get <code>POST http://127.0.0.1:8000/admin/auth/user/ net::ERR_CONNECTION_REFUSED</code> as an error on the site and a <code>Uncaught (in promise) Error: Network Error at createError (createError.js?2d83:16) at XMLHttpRequest.handleError (xhr.js?b50d:84)</code> error right after.</p>
  <p>The login method I'm attempting to use that's giving the errors:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>login() {
        axios.post('http://127.0.0.1:8000/admin/auth/user/', {
          username: this.username,
          password: this.password,
        })
            .then(resp =&gt; {
  
              this.token = resp.data.token;
              console.log(this.token)
              localStorage.setItem('user-token', resp.data.token)
            })
      }</code></pre>
  </div>
  </div>
  </p>
  <p>The full error:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>POST http://127.0.0.1:8000/admin/auth/user/ net::ERR_CONNECTION_REFUSED
  dispatchXhrRequest  @   xhr.js?b50d:177
  xhrAdapter  @   xhr.js?b50d:13
  dispatchRequest @   dispatchRequest.js?5270:52
  Promise.then (async)        
  request @   Axios.js?0a06:61
  Axios.&lt;computed&gt;    @   Axios.js?0a06:87
  wrap    @   bind.js?1d2b:9
  login   @   Header.vue?0418:44
  $data.token.Object.onClick._cache.&lt;computed&gt;._cache.&lt;computed&gt;  @   Header.vue?0418:17
  callWithErrorHandling   @   runtime-core.esm-bundler.js?5c40:154
  callWithAsyncErrorHandling  @   runtime-core.esm-bundler.js?5c40:163
  invoker @   runtime-dom.esm-bundler.js?830f:333</code></pre>
  </div>
  </div>
  </p>
  <p>settings.py:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>"""
  Django settings for DB_django_Project project.
  
  Generated by 'django-admin startproject' using Django 3.1.7.
  
  For more information on this file, see
  https://docs.djangoproject.com/en/3.1/topics/settings/
  
  For the full list of settings and their values, see
  https://docs.djangoproject.com/en/3.1/ref/settings/
  """
  # This is a test comment. Please remove this.
  from pathlib import Path
  
  # Build paths inside the project like this: BASE_DIR / 'subdir'.
  BASE_DIR = Path(__file__).resolve().parent.parent
  
  # Quick-start development settings - unsuitable for production
  # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
  
  # SECURITY WARNING: keep the secret key used in production secret!
  SECRET_KEY = 'somethinsecret'
  
  # SECURITY WARNING: don't run with debug turned on in production!
  DEBUG = True
  
  ALLOWED_HOSTS = []
  
  # Application definition
  
  INSTALLED_APPS = [
      'DB_Vue_Project.apps.DbVueProjectConfig',
      'myapi.apps.MyapiConfig',
      'django.contrib.admindocs',
      'rest_framework',
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'corsheaders',
      'rest_framework.authtoken',
      'rest_framework_simplejwt.token_blacklist',
  
  ]
  
  CORS_ORIGIN_WHITELIST = (
      'https://localhost:8080',
      'https://127.0.1:8080',
  )
  
  REST_FRAMEWORK = {
      'DEFAULT_AUTHENTICATION_CLASSES': [
          # basic and session are what we are currently using
          'rest_framework.authentication.BasicAuthentication',
          'rest_framework.authentication.SessionAuthentication',
          # token authentication failed I believe
          'rest_framework.authentication.TokenAuthentication',
          'rest_framework_simplejwt.authentication.JWTAuthentication'
      ]
  }
  
  CORS_ORIGIN_ALLOW_ALL = True
  
  # CORS_ALLOW_HEADERS = list(default_headers) + [
  #     'contenttype',
  # ]
  
  MIDDLEWARE = [
      'corsheaders.middleware.CorsMiddleware',
      'django.middleware.security.SecurityMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
  ]
  
  ROOT_URLCONF = 'DB_django_Project.urls'
  
  TEMPLATES = [
      {
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          'DIRS': [
              str(BASE_DIR.joinpath('templates'))
          ],
          'APP_DIRS': True,
          'OPTIONS': {
              'context_processors': [
                  'django.template.context_processors.debug',
                  'django.template.context_processors.request',
                  'django.contrib.auth.context_processors.auth',
                  'django.contrib.messages.context_processors.messages',
              ],
          },
      },
  ]
  
  WSGI_APPLICATION = 'DB_django_Project.wsgi.application'
  
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.mysql',
          'NAME': 'mystdb',
          'HOST': 'fancy.stuff.us-east-2.rds.amazonaws.com',
          'PORT': '3306',
          'USER': 'username',
          'PASSWORD': 'password',
      },
      'OPTIONS': {
          'init_command': "SET sql_mode ='STRICT_TRANS_TABLES'",
      },
  }
  # settings.py file
  # Database
  # https://docs.djangoproject.com/en/2.1/ref/settings/#databases
  
  
  # Password validation
  # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
  
  AUTH_PASSWORD_VALIDATORS = [
      {
          'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
      },
  ]
  
  # Internationalization
  # https://docs.djangoproject.com/en/3.1/topics/i18n/
  
  LANGUAGE_CODE = 'en-us'
  
  TIME_ZONE = 'UTC'
  
  USE_I18N = True
  
  USE_L10N = True
  
  USE_TZ = True
  
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/3.1/howto/static-files/
  
  STATIC_URL = '/static/'</code></pre>
  </div>
  </div>
  </p>
  <p>I've looked around in Django documentation and around stackoverflow for a couple hours and haven't found any solutions. Any assistance, critiques, comments, or questions would be appreciated. I'd be more than happy to provide any additional information needed.</p>