Django rest framework 如何在django rest框架中发布图像文件

Django rest framework 如何在django rest框架中发布图像文件,django-rest-framework,python-unittest,Django Rest Framework,Python Unittest,我正在对我的rest框架API、我的模型进行单元测试: class attach(): attachment = models.ImageField name = models.CharField 然后我尝试通过我定义的API(此处未显示标准序列化程序)发布到is 我得到以下堆栈跟踪 ValueError: The 'attachment' attribute has no file associated with it. 如何将密钥附件与文件关联?创建请求时,请确保设置fo

我正在对我的rest框架API、我的模型进行单元测试:

class attach():
    attachment = models.ImageField
    name = models.CharField
然后我尝试通过我定义的API(此处未显示标准序列化程序)发布到is

我得到以下堆栈跟踪

ValueError: The 'attachment' attribute has no file associated with it.

如何将密钥附件与文件关联?创建请求时,请确保设置
format=“multipart”

[...]
c.post('/customers/wishes/', {'name': 'fred', 'attachment': fp}, format='multipart')
资料来源:

[...]
c.post('/customers/wishes/', {'name': 'fred', 'attachment': fp}, format='multipart')