Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This backend doesn't support absolute paths. #30

Closed
satya-root opened this issue May 19, 2021 · 2 comments
Closed

This backend doesn't support absolute paths. #30

satya-root opened this issue May 19, 2021 · 2 comments

Comments

@satya-root
Copy link

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
Copy link

youcef-zaidi commented May 30, 2021

Solved for me

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

@klis87
Copy link
Owner

klis87 commented Feb 8, 2022

Closing as this seems to be solved.

@klis87 klis87 closed this as completed Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants