![](/img/trans.png)
[英]TypeError: expected str, bytes or os.PathLike object, not list convert
[英]admin Panel: TypeError: expected str, bytes or os.PathLike object, not list
尝试在http://127.0.0.1:8000/admin/ 中上传图片时出现此错误:TypeError: expected str, bytes or os.PathLike object, not list [23/Oct/2020 12:15: 22]“POST /admin/store/category/4/change/HTTP/1.1”500 166634
我使用的是 MacOS 10.15.7 Python 3.9 Django 3.1.2 熊猫 1.1.3
from django.db import models
class Category(models.Model):
name = models.CharField(max_length=250, unique=True)
slug = models.SlugField(max_length=250, unique=True)
description = models.TextField(blank=True)
image = models.ImageField(upload_to='category', blank=True)
class Meta:
ordering = ('name',)
verbose_name = 'category'
verbose_name_plural = 'categories'
def __str__(self):
return self.name
class Product(models.Model):
name = models.CharField(max_length=250, unique=True)
slug = models.SlugField(max_length=250, unique=True)
description = models.TextField(blank=True)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
price = models.DecimalField(max_digits=10, decimal_places=2)
image = models.ImageField(upload_to='product', blank=True)
stock = models.IntegerField
available = models.BooleanField(default=True)
created = models.DateField(auto_now_add=True)
updated = models.DateField(auto_now=True)
你知道如何解决它吗?
谢谢
当您指定upload_to='product'
它需要 MEDIA_ROOT。 请尝试以下操作:
'media'
和'media/product'
文件夹settings.py
底部添加下面的代码MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = 'media/'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.