在本地工作良好,但在服务器上无法上传图像

2024-04-19 08:22:12 发布

您现在位置:Python中文网/ 问答频道 /正文

当用户上传图像并提交注册表单时,我正在尝试将图像保存到文件夹中。你知道吗

在型号.py你知道吗

image = models.ImageField(upload_to=upload_location, null=True, blank=True)

我使用了一个函数upload_location来上传图像,这里就是

def upload_location(instance, filename):
    UserModel = instance.__class__
    new_id = UserModel.objects.order_by("id").last().id + 1
    return "user/%s/%s" %(new_id,filename)

它在localhost中工作得很好,但当我将代码推送到服务器时,它甚至没有运行函数upload_location。我做错什么了?你知道吗

编辑: 才知道真正的问题。服务器上没有上载大于15kb的文件。这是django问题还是服务器问题?你知道吗


Tags: instance函数用户图像服务器文件夹idtrue