«Ошибка подключения: [ошибка WinError 10053] Установленное соединение было прервано программным обеспечением на вашей хост-машине», когда я попытался добавить изображение в бд

#python #django

Вопрос:

Ниже приведен мой Джанго models.py файл. Я получаю эту ошибку, когда пытаюсь загрузить изображение в БД. Это показывает, что сервер не может быть достигнут, и выдает ошибку в cmd. Когда я сохраняю изображение без загрузки, оно отлично работает. Кто-нибудь может помочь мне решить эту проблему?

 # Create your models here.
from django.contrib.auth.models import AbstractUser, BaseUserManager
from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
import uuid
from django.db.models.signals import post_save, post_delete
from django.utils.timezone import now

class UserManager(BaseUserManager):
    """Define a model manager for User model with no username field."""

    use_in_migrations = True

    def _create_user(self, email,username, first_name, last_name, password, **extra_fields):
        """Create and save a User with the given email and password."""
        if not email:
            raise ValueError('The given email must be set')
        email = self.normalize_email(email)
        user = self.model(email=email,username=username,first_name=first_name,last_name=last_name, **extra_fields)
        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_user(self, email, password=None, **extra_fields):
        """Create and save a regular User with the given email and password."""
        extra_fields.setdefault('is_staff', False)
        extra_fields.setdefault('is_superuser', False)
        return self._create_user(email, password, **extra_fields)

    def create_superuser(self, email, password, **extra_fields):
        """Create and save a SuperUser with the given email and password."""
        extra_fields.setdefault('is_staff', True)
        extra_fields.setdefault('is_superuser', True)

        if extra_fields.get('is_staff') is not True:
            raise ValueError('Superuser must have is_staff=True.')
        if extra_fields.get('is_superuser') is not True:
            raise ValueError('Superuser must have is_superuser=True.')

        return self._create_user(email, password, **extra_fields)


class User(AbstractUser):
    """User model."""

    username = models.CharField(max_length=200, null=True)
    first_name = models.CharField(max_length=200, null=True)
    last_name = models.CharField(max_length=200, null=True)
    email = models.EmailField(('email address'), unique=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = UserManager()


class Post(models.Model):
    """post model"""
    id = models.UUIDField(primary_key=True,default=uuid.uuid4,editable=False)
    name = models.CharField(max_length=100,null=False)
    picture = models.ImageField(upload_to='images/', verbose_name='Picture',blank=True)
    file = models.FileField(upload_to='files/',blank=True,verbose_name='File')
    HelpRel = models.TextChoices('HelpRel','Myself Family Friends')
    relation = models.CharField(blank=True, choices=HelpRel.choices,max_length=10)
    description = models.CharField(max_length=300,null=True)
    age = models.PositiveIntegerField(null=True, blank=True)
    posted = models.DateTimeField(default=now)
    user = models.ForeignKey(User,on_delete=models.CASCADE)
 
 Exception occurred during processing of request from ('127.0.0.1', 59879)
Traceback (most recent call last):
  File "C:UsersbbaraAppDataLocalProgramsPythonPython39libsocketserver.py", line 650, in process_request_thread
    self.finish_request(request, client_address)
  File "C:UsersbbaraAppDataLocalProgramsPythonPython39libsocketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:UsersbbaraAppDataLocalProgramsPythonPython39libsocketserver.py", line 720, in __init__
    self.handle()
  File "C:UsersbbaraEnvironmentlibsite-packagesdjangocoreserversbasehttp.py", line 174, in handle
    self.handle_one_request()
  File "C:UsersbbaraEnvironmentlibsite-packagesdjangocoreserversbasehttp.py", line 182, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
  File "C:UsersbbaraAppDataLocalProgramsPythonPython39libsocket.py", line 704, in readinto
    return self._sock.recv_into(b)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine