I did just that but now this error popped up on my visual code. Will i have 
to go into my setting.py file and create a new app for my models.py?

*Exception has occurred: ImproperlyConfigured*

*Requested setting INSTALLED_APPS, but settings are not configured. You 
must either define the environment variable DJANGO_SETTINGS_MODULE or call 
settings.configure() before accessing settings.*
* File "C:\Users\delvi\django_project\users\models.py", line 2, in <module> 
from django.contrib.auth.models import User*

I also ran the web page but the same issue occurred. Would it just be the 
placement of my code that i made a mistake on?

Models.py file 
*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)*
*        file = open('media.ext')*
        
*        if img.height > 300 or img.width > 300:*
*            output_size = (300, 300)*
*            img.thumbnail(output_size)*
*            img.save(self.image.path)*


On Thursday, March 24, 2022 at 7:19:00 AM UTC-7 shahsawoo...@gmail.com 
wrote:

> 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/2f327270-7b90-43d1-88ce-65a52d4ed558n%40googlegroups.com.

Reply via email to