Django提供了一种在FileFields上编写测试而又不会在真实文件系统中造成麻烦的好方法-使用SimpleUploadedFile。
from django.core.files.uploadedfile import SimpleUploadedFilemy_model.file_field = SimpleUploadedFile('best_file_eva.txt', b'these are the contents of the txt file')
这是django的神奇功能之一,即不会在文档中显示:)。但是这里提到了它。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)