klis87 / django-cloudinary-storage

Django package that provides Cloudinary storages for both media and static files as well as management commands for removing unnecessary files.
MIT License
131 stars 26 forks source link

This backend doesn't support absolute paths. #30

Closed satya-root closed 2 years ago

satya-root commented 3 years ago

I am trying to upload an image following the documentation but getting the error : This backend doesn't support absolute paths. here is my code. models.py `from django.db import models

from django.contrib.auth.models import User from multiselectfield import MultiSelectField

Create your models here.

class profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) CLASS_CHOICES = [ ('Class - IX', 'Class - IX'), ('Class X', 'Class X'), ] standard = models.CharField(choices=CLASS_CHOICES, default='Class X', max_length=10) roll_number = models.SmallIntegerField(blank=True,primary_key=True)

bio = models.TextField(max_length=500, blank=True)

# location = models.CharField(max_length=30, blank=True)
birth_date = models.DateField(null=True, blank=True)
image = models.ImageField(upload_to='profile_pics/', default='img_avatar.png')

class Meta:
    permissions = [
        ('is_student', 'User is student')
    ]
        # ('is_teacher', 'User is teacher'),
def __str__(self):
    return f'{self.roll_number}. {self.user.first_name}  {self.user.last_name}' 

` views.py def handle_save(request): if request.method == 'POST': profile_pic = request.FILES['new-profile-img'] print(profile_pic)

    try:
        instance = profile.objects.get(user=request.user)
    except:
        instance = teacher.objects.get(user= request.user)

    finally:    
        print(instance.image.path)
        instance.image = profile_pic
        instance.save()
        return redirect('profile')
youcef-zaidi commented 3 years ago

Solved for me

you have to omit the .path write print(instance.image) instead of print(instance.image.path)

klis87 commented 2 years ago

Closing as this seems to be solved.