from django.db import models from django.db.models.signals import pre_delete from django.dispatch import receiver # Create your models here. class IMG(models.Model): img = models.ImageField(upload_to='img') # 地址 name = models.CharField(max_length=20) # 删除方法重载 @receiver(pre_delete, sender=IMG) def file_delete(instance, **kwargs): instance.img.delete(False) # print("delete", instance.img)