python - django应用程序多个硬盘驱动器[Errno 18]无效的跨设备链接

标签 python django server debian-based

我在 Debian 服务器上有一个 Django 应用程序,并且当前磁盘上的当前 site_media 目录已满。所以我想将文件上传到第二个磁盘上。服务器上的路径是/disk :

        obj = form.save(commit=False)
        obj.user_id = self.request.user.pk
        obj.save()
        initial_path = obj.file.path
        print(initial_path)
        new = settings.MEDIA_ROOT_NEW + obj.file.name
        print(new)
        os.rename(initial_path,new)
        shutil.move(initial_path, new)

在我的settings.py 中我有:

        MEDIA_ROOT = os.path.join(PROJECT_PATH, 'site_media/')
        MEDIA_ROOT_NEW = '/disk/site_media/'

我仍然收到错误: django [Errno 18]无效的跨设备链接

有什么想法吗?

最佳答案

os.rename() 可能会失败 across不同的文件系统。

The operation may fail on some Unix flavors if src and dst are on different filesystems.

shut.move() should工作

If the destination is on the current filesystem, then os.rename() is used. Otherwise, src is copied (using shutil.copy2()) to dst and then removed.

但是在 shutil.move(initial_path, new) 之前有一个 os.rename(initial_path,new) 。删除第一个 os.rename() ,它应该可以工作。

关于python - django应用程序多个硬盘驱动器[Errno 18]无效的跨设备链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40088442/

相关文章:

python - 警告 :tensorflow :`write_grads` will be ignored in TensorFlow 2. 0 为 `TensorBoard` 回调

GemFury 包的 Python setup.py 依赖链接

python : How to import a module if I have its path as a string?

python - 如何处理类层次结构中的Python装饰器?

python - Django 休息框架 : redirect to Amazon S3 fails when using Token Authentication

php - 在并行 plesk 服务器中安装 codeigniter

python - 对堆叠的 pandas 数据框进行子集化

django - Tastypie APIKey 认证

python - Python 中以 null 结尾的字符串转换为 Int

java - 与单独的线程读/写操作聊天。写入线程立即关闭