📜  如何在 django 中模拟上传的文件? - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:18.429000             🧑  作者: Mango

代码示例1
from django.core.files.uploadedfile import SimpleUploadedFile

# To mock a simple raw text file
mock_profile_image = SimpleUploadedFile('simple_file.txt', 'raw-text', content_type='text')

# To mock an image
mock_profile_image = SimpleUploadedFile('profile_img.jpg', b'0xfwsf', content_type='image/jpeg')