美文网首页
No such file or directory:获取不到文件

No such file or directory:获取不到文件

作者: 不能没有音乐 | 来源:发表于2021-04-20 09:20 被阅读0次

使用绝对位置
django的setting中

import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_ROOT = os.path.join(BASE_DIR, 'djearth/static')

在要用的地方引用

from django.conf import settings
        with open(str(settings.STATIC_ROOT) + '/dae1/1.png', 'r') as file:
            a = file.read()

相关文章

网友评论

      本文标题:No such file or directory:获取不到文件

      本文链接:https://www.haomeiwen.com/subject/odfwlltx.html