[英]request.FILES empty uploading image on Django
這是我的HTML發送請求,打印request.FILES
返回<MultiValueDict: {}>
。 另外我會問我如何保存我帶電的圖片(只可以form.save()
嗎?)
<form action="send_news" method="POST" encrypt="multipart/form-data">
{% csrf_token %} {{ form.as_p }}
<p>
<label for="news_title">Your name: </label>
<input id="news_title" type="text" name="news_title" value="newtitle">
</p>
<p>
<label for="news_small_description">Your name: </label>
<input name="news_small_description" id="news_small_description" value="news_small_description">
</p>
<p>
<label for="news_description">Your name: </label>
<input name="news_description" id="news_description" value="news_description">
</p>
<p>
<label for="news_image">Your name: </label>
<input id="news_image" type="file" class="" name="news_image">
</p>
<input type="submit" value="Submit" />
</form>
打印request.FILES返回<MultiValueDict: {}>
。 另外我會問我如何保存我帶電的圖片(只可以form.save()
嗎?)
問題是您正在使用encrypt
但需要使用enctype
例如
<form action="send_news" method="POST" enctype="multipart/form-data">
請參閱enctype ='multipart / form-data'是什么意思? 有關更多信息(如果需要)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.