我想将 python-docx 文档保存到Ubuntu上具有777特权的目录中,但出现此错误:[Errno 13] Permission denied: 'media/Rooming Grand Oasis Cancun 2018-11-01-2018-11-30.docx'
。
这是 Django Rest Framework 视图的代码:
def get_hotel_document(self, request, start_date, end_date, confirmed, hotel, bookings):
from django.core.files import File
from django.urls import reverse
from docx import Document
from docx.shared import Inches, Pt
document = Document()
section = document.sections[-1]
section.left_margin = Inches(0.5)
section.right_margin = Inches(0.5)
style = document.styles['Normal']
font = style.font
font.name ='Arial'
font.size = Pt(10)
... more code ...
file_name = "media/Rooming {} {}-{}.docx".format(hotel, start_date, end_date)
document.save(file_name)
return file_name
在这里您可以看到目录的权限:
调用document.save(file_name)
时出错。