Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 未调用post_delete_Python_Django_Python 3.x - Fatal编程技术网

Python 未调用post_delete

Python 未调用post_delete,python,django,python-3.x,Python,Django,Python 3.x,Django 1.11.7 Python 3.6.5 我试图实现以下代码,以便在删除模型时删除文件。 但是不调用post_delete @receiver(post_delete, sender=HogeFileModel, dispatch_uid=uuid.uuid4()) @receiver(post_delete, sender=FugaFileModel, dispatch_uid=uuid.uuid4()) def auto_delete_file_on_delete_part_fi

Django 1.11.7 Python 3.6.5

我试图实现以下代码,以便在删除模型时删除文件。 但是不调用post_delete

@receiver(post_delete, sender=HogeFileModel, dispatch_uid=uuid.uuid4())
@receiver(post_delete, sender=FugaFileModel, dispatch_uid=uuid.uuid4())
def auto_delete_file_on_delete_part_file(sender, instance, using, **kwargs):
    print('Called post_delete')
    if instance.file:
        if os.path.isfile(instance.file.path):
            os.remove(instance.file.path)

如何修复它?

你怎么知道它没有被调用?@Lemayzeur如果在调用HogeFileModel.objects.get(pk=~~).delete()时被打印为“called post\u delete”,你是否尝试过
pre\u delete()
以及为什么要添加两次装饰器?@Lemayzeur只是尝试过,但没有被调用><为什么要添加两次装饰器?>>我的服务器程序有一些类似的模型。所以我添加了两次或更多的decorator。它是否在单独的文件(比如signals.py)中?