Getting 127.0.0.1 refused to connect. when try to add new fk in django admin
Hi i am always getting 127.0.0.1 refused to connect. error on popup when i tring to add new fk in existed model using + in django admin . i am using "admin_interface",and some other package releted to django-admin themes which are listed in installed apps ,is that reason that i am getting this error.
i try to pass "*" in ALLOWED_HOSTS in setting.py ,
when i am trying that process in google chrome browser it show as i share in image 1 but when i tring to do same with firefox it is shared in second image .
my setting.py file
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = ''
DEBUG = True
ALLOWED_HOSTS = ['*']
INSTALLED_APPS = [
# 'grappelli',
"admin_interface",
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mdeditor',
"colorfield",
'drf_yasg',
"rest_framework",
'django_filters',
"corsheaders",
"storages",
'rest_framework_swagger',
'authentication',
'mails',
'authors',
'book_store',
'institude_home_page',
]
MIDDLEWARE = [
'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 = 'vani_prakashan.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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 = 'vani_prakashan.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
REST_FRAMEWORK = {
# 'DEFAULT_AUTHENTICATION_CLASSES': [
# 'apps.authentication.backends.JWTAuthentication',
# ],
'DEFAULT_AUTHENTICATION_CLASSES': (
'authentication.backends.JWTAuthentication',
),
'DEFAULT_FILTER_BACKENDS': (
'django_filters.rest_framework.DjangoFilterBackend',
),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 15,
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
}
# 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',
},
]
AUTH_USER_MODEL = 'authentication.User'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
# Base url to serve media files
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
STATIC_ROOT=os.path.join(BASE_DIR, 'static/')
Seems like a problem with iframe's Clickjacking Protection. The Django docs say:
By default, the middleware will set the X-Frame-Options header to DENY for every outgoing HttpResponse. If you want any other value for this header instead, set the X_FRAME_OPTIONS setting.
Try this setting in order to allow iframes from the same ip addres as the main page:
X_FRAME_OPTIONS = 'SAMEORIGIN'
You can read more at: https://docs.djangoproject.com/en/4.0/ref/clickjacking/#setting-x-frame-options-for-all-responses