【问题标题】:SuspiciousOperation :Attempted access to path default_storage djangoSuspiciousOperation:尝试访问路径 default_storage django
【发布时间】:2013-07-24 19:15:41
【问题描述】:

我正在尝试将PDF 保存到我的project 中的文件夹中,当我尝试保存PDF 时,folder 具有权限read, write 我收到此错误:

SuspiciousOperation:试图访问 /opt/django_apps/inscripcion/solicitudes/filename

这是我的简单代码:

 contenido = "Simple code"
 file_name = "/opt/django_apps/inscripcion/solicitudes/filename"
 path = default_storage.save(file_name, ContentFile(contenido))

我在RedHat 上使用python2.7mod_pythondjango1.3

【问题讨论】:

    标签: python django mod-python django-storage django-errors


    【解决方案1】:

    实际的异常是在第 76 行的 django/utils/_os.py 中引发的:

    raise ValueError('The joined path (%s) is located outside of the base '
                     'path component (%s)' % (final_path, base_path))
    

    base_path 对应于default_storagesettings.MEDIA_ROOT

    我建议用

    创建FileSystemStorage
    file_storage = FileSystemStorage(location = '/opt/django_apps/inscripcion/solicitudes/')
    

    然后

    contenido = "Simple code"
    file_name = "filename"
    path = file_storage.save(file_name, ContentFile(contenido))
    

    【讨论】:

    • 我会在现在尝试修复built-in open 函数:D
    • 好吧,最简单的决定胜过一切:)
    猜你喜欢
    • 1970-01-01
    • 2015-03-19
    • 2015-02-04
    • 2018-12-28
    • 2011-04-07
    • 1970-01-01
    • 2012-07-06
    • 2013-07-10
    • 2011-11-29
    相关资源
    最近更新 更多