Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从Django向外部API REST发送文件_Python_Django_Rest_Api - Fatal编程技术网

Python 从Django向外部API REST发送文件

Python 从Django向外部API REST发送文件,python,django,rest,api,Python,Django,Rest,Api,我正在尝试将一个文件从DJANGO表单发送到API REST服务,如果我只发送文本,它可以工作,但我需要发送一个文件,我尝试了我找到的所有内容,但没有工作 这是我的表格: class Publicacion(forms.Form): publicacion = forms.CharField(label=False, widget=forms.Textarea(attrs={'rows': '3', 'cols': '40'})) imagen = forms.FileField(requi

我正在尝试将一个文件从DJANGO表单发送到API REST服务,如果我只发送文本,它可以工作,但我需要发送一个文件,我尝试了我找到的所有内容,但没有工作

这是我的表格:

class Publicacion(forms.Form):

publicacion = forms.CharField(label=False,  widget=forms.Textarea(attrs={'rows': '3', 'cols': '40'}))
imagen = forms.FileField(required=False)
这是该表单的html:

            <form name="publicion" enctype="multipart/form-data" id="publicacion" method="POST">{% csrf_token %}
            <div class="post post_form" style="padding:0;">
                {{ formpublicar|crispy }}
                <button class="post_form_extra"></button>
                <input value=" " type="submit" class="post_form_submit" name="publicar"/>
            </div>

            </form>

您应该使用
请求

requests.post(url, files=files, data=data)

您应该使用
请求

requests.post(url, files=files, data=data)