title: DisallowedRedirect: Unsafe redirect to URL with protocol '127.0.0.1'
body: <p>I am trying to get my Django application running, and stuck at the following error at all of my endpoints (except the root endpoint):</p>
  
  <pre><code>DisallowedRedirect at /coffeeshop/items
  Unsafe redirect to URL with protocol '127.0.0.1'
  </code></pre>
  
  <p>With the server logs saying:</p>
  
  <pre><code>Unsafe redirect to URL with protocol '127.0.0.1'
  Bad Request: 127.0.0.1:80/myapp/items
  [01/Jun/2020 16:12:36] "GET /myapp/items HTTP/1.1" 400 65131
  </code></pre>
  
  <p>Here is the <code>myapp/items</code> view:</p>
  
  <pre><code>class ItemViewSet(ReadOnlyModelViewSet):
      model = Item
      queryset = Item.objects.all()
      serializer_class = ItemSerializer
      filter_backends = (filters.DjangoFilterBackend,)
      filterset_class = ItemFilterSet
  </code></pre>
  
  <p>The server is running on <a href="http://127.0.0.1:8000/" rel="nofollow noreferrer">http://127.0.0.1:8000/</a>, and I am not trying to redirect anything in any of my views. As can be seen in the logs, the server tries to redirect the request to <code>:80</code> port, and I don't understand why.</p>
  
  <p>Here is my settings file, too, for reference (maybe there are problems that I cannot see):</p>
  
  <pre><code>ALLOWED_HOSTS = [
      'localhost',
      'localhost:3000',
      '127.0.0.1',
      '0.0.0.0'
  ]
  
  # Application definition
  
  INSTALLED_APPS = [
      # 'jet_django',
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'myapp.apps.MyappConfig',
      'rest_framework',
      'phonenumber_field',
      'django_filters',
      'corsheaders',
  ]
  
  MIDDLEWARE = [
      'django.middleware.security.SecurityMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      'corsheaders.middleware.CorsMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
  ]
  
  ROOT_URLCONF = 'myapp.urls'
  
  TEMPLATES = [
      {
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          'DIRS': [os.path.join(BASE_DIR, '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 = 'myapp.wsgi.application'
  
  # Database
  # https://docs.djangoproject.com/en/3.0/ref/settings/#databases
  
  DATABASES = {
      "default": {
          "ENGINE": "django.db.backends.postgresql",
          "NAME": os.environ.get("POSTGRES_DB"),
          "USER": os.environ.get("POSTGRES_USER"),
          "PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
          "HOST": os.environ.get("POSTGRES_HOST"),
          "PORT": os.environ.get("POSTGRES_PORT"),
      }
  }
  
  # Password validation
  # https://docs.djangoproject.com/en/3.0/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',
      },
  ]
  
  REST_FRAMEWORK = {
      'DEFAULT_FILTER_BACKENDS': (
          'django_filters.rest_framework.DjangoFilterBackend',
      ),
      'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
      'PAGE_SIZE': 100
  }
  
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/3.0/howto/static-files/
  
  STATIC_URL = '/static/'
  STATIC_ROOT = os.path.join(BASE_DIR, "static/")
  MEDIA_ROOT = os.path.join(STATIC_ROOT, 'media')
  MEDIA_URL = '/media/'
  
  # CORS
  CORS_ALLOW_METHODS = ('DELETE', 'GET', 'PATCH', 'POST', 'PUT')
  CORS_ORIGIN_WHITELIST = (
      'http://localhost',
      'http://127.0.0.1',
  )
  CORS_ALLOW_CREDENTIALS = True
  </code></pre>