I am trying to build a site using rest_framework djoser and i am new to it, I am getting a connection refused error
Meanwhile the username , email and the other are saved in the db but when i post it i am getting this error , if i use the same user email it says it exists if i try new one it gives a connection error
I shared my code below
settings.py
"""
Django settings for backend project.
Generated by 'django-admin startproject' using Django 5.0.4.
For more information on this file, see
https://docs.djangoproject.com/en/5.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.0/ref/settings/
"""
from os import getenv,path
from pathlib import Path
from django.core.management.utils import get_random_secret_key
import dotenv
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
dotenv_file = BASE_DIR / '.env.local'
if path.isfile(dotenv_file):
dotenv.load_dotenv(dotenv_file)
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
# SECRET_KEY = 'django-insecure-g@8#ffje0md2c(_t_1bf9s)7s80ysl7=g^^mf8^&kjy)*crn%r'
SECRET_KEY = getenv('DJANGO_SECRET_KEY', get_random_secret_key())
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = getenv('DEBUG','False') == 'True'
ALLOWED_HOSTS = getenv( 'DJANGO_ALLOWED_HOSTS', '127.0.0.1,localhost').split(",")
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'rest_framework',
'djoser',
'users',
]
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 = 'backend.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 = 'backend.wsgi.application'
# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/5.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',
},
]
# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/
STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'static'
MEDIA_UTL = 'media'
MEDIA_ROOT = BASE_DIR / 'media'
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
],
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticated'
]
}
DJOSER ={
'PASSWORD_RESET_CONFIRM_URL' : 'password-reset/{uid}/{token}',
'SEND_ACTIVATION_EMAIL' : True,
'SEND_CONFIRMATION_EMAIL': True,
'ACTIVATION_URL' : 'activation/{uid}/{token}',
'USER_CREATE_PASSWORD_RETYPE' : True,
'PASSWORD_RESET_CONFIRM_RETYPE' : True,
'TOKEN_MODEL' : None,
}
# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
AUTH_USER_MODEL = 'users.UserAccount'
backend url
from django.contrib import admin
from django.urls import path , include
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('djoser.urls')),
path('api/' , include('djoser.urls.jwt')),
]
This is my models.py
from django.db import models
from django.contrib.auth.models import BaseUserManager, AbstractBaseUser , PermissionsMixin
class UserAccountManager(BaseUserManager):
def create_user(self, email, password=None, **kwargs):
if not email:
raise ValueError("Users must have an email address")
email = self.normalize_email(email)
email = email.lower()
user = self.model(
email= email,
**kwargs,
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, password=None, **kwargs):
user = self.create_user(
email,
password=password,
**kwargs,
)
user.is_admin = True
user.is_superuser = True
user.save(using=self._db)
return user
class UserAccount(AbstractBaseUser , PermissionsMixin):
First_Name = models.CharField(max_length=255)
Last_Name = models.CharField(max_length=255)
email = models.EmailField( max_length=255,unique=True,)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
is_superuser = models.BooleanField(default=False)
objects = UserAccountManager()
USERNAME_FIELD = "email"
REQUIRED_FIELDS = ['First_Name', 'Last_Name']
def __str__(self):
return self.email
what is the cause of this error
Please help me asap