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


  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))


我在python2.7mod_python上使用django1.3RedHat

最佳答案

实际异常在第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_pathdefault_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))

09-10 17:58