Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个自定义 ModelAdmin 将上传的文件解压缩到 /tmp 并将解压缩的文件设置为模型中的 FileFieldmymodel.myfilefield = File(open(path_to_file))
mymodel.myfilefield = File(open(path_to_file))
事情是,在这样做之后,新文件被复制到<MEDIA_ROOT>/<upload_to>/tmp/<filename>
<MEDIA_ROOT>/<upload_to>/tmp/<filename>
这是不希望的。为什么要附加“tmp”路径?
谢谢
问题在于 to_upload 方法,我正在获取文件名并按原样使用它。
解决方法是:filename = os.path.basename(filename)并使用它
filename = os.path.basename(filename)