Home > Back-end >  TypeError: _getfullpathname: path should be string, bytes or os.PathLike, not list (Django)
TypeError: _getfullpathname: path should be string, bytes or os.PathLike, not list (Django)

Time:10-31

I am trying to add a profile photo to the client through the 'Customer' model in the administration panel.

models.py

from django.contrib.auth.models import User

class Customer(models.Model):
    user = models.OneToOneField(User, null=True, on_delete=models.CASCADE)
    name = models.CharField(max_length=200, null=True)
    phone = models.CharField(max_length=200, null=True)
    email = models.CharField(max_length=200, null=True)
    profile_pic = models.ImageField(null=True, blank=True)
    date_created = models.DateTimeField(auto_now_add=True, null=True)
    
    def __str__(self):
        return self.name

settings.py

STATIC_URL = '/static/'

MEDIA_URL = '/imagenes/'

STATICFILES_DIRS = [
    BASE_DIR / "static",
]
 
MEDIA_ROOT = [BASE_DIR/'static/images']

I think I have an error in setting static file paths; the truth is that I understand very little the way in which I should configure it and I do not understand why the error occurred .. Please, someone who can help me

CodePudding user response:

settings.MEDIA_ROOT should be a path and not a list, you need to change your setting. It's also not a good idea to have your static and media directories overlapping, you should use a unique directory for your media

MEDIA_ROOT = BASE_DIR / 'media'

https://docs.djangoproject.com/en/3.2/ref/settings/#media-root

  • Related