1. According to your model, you meant the models.py file and default.jpg 
are in same directory.
=> But according to the error it smells that they are not same directory, 
so try to point to the exact relative path of the image.

On Thursday, March 24, 2022 at 10:10:13 AM UTC+5 Delvin Alexander wrote:

> would anyone know why this is popping up for me and where can i go to 
> solve this issue?
>
> - [Errno 2] No such file or directory: 
> 'C:\\Users\\delvi\\django_project\\media\\default.jpg'
>
> *Here is my models.py:*
> from django.db import models
> from django.contrib.auth.models import User
> from PIL import Image
>
> class Profile(models.Model):
>     user = models.OneToOneField(User, on_delete=models.CASCADE)
>     image = models.ImageField(default='default.jpg', 
> upload_to='profile_pics')
>     
>     def __str__(self):
>         return f'{self.user.username} Profile'
>
>     def save(self, *args, **kwargs):
>         super(Profile, self).save(*args, **kwargs)
>         
>         img = Image.open(self.image.path)
>         
>         if img.height > 300 or img.width > 300:
>             output_size = (300, 300)
>             img.thumbnail(output_size)
>             img.save(self.image.path)
>
>
> *And here is my signlas.py:*
> from django.db.models.signals import post_save
> from django.contrib.auth.models import User
> from django.dispatch import receiver
> from .models import Profile
>
>
> @receiver(post_save, sender=User)
> def create_profile(sender, instance, created, **kwargs):
>     if created:
>         Profile.objects.create(user=instance)
>         
>         
> @receiver(post_save, sender=User)
> def save_profile(sender, instance, **kwargs):
>     instance.profile.save()
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0bb7a587-ee52-43a7-97ae-9971b4856196n%40googlegroups.com.

Reply via email to