我不知道爲什麼發生這種情況:Django中,正常形態後沒有文件數據發送到服務器,
我在POST形式發送文件數據,但所有的時間,它說:
Key 'file' not found in <QueryDict:
{
u'datum': [u'aaa'],
u'csrfmiddlewaretoken': [u'USAbRrgU92yj7KFpZHuxf9bWufgnwC4N'],
u'anzeige': [u' aaaa'],
u'titel': [u' aaa']
}
這是我的html:
<form id="myform" action="/anzeige_save/" method="post" enctype="multipart/form-data">
{% csrf_token %}
<textarea style="width: 450px" id="titel" name="titel"> </textarea>
<textarea name="anzeige" id="anzeige"
style="height: 180px; width: 450px"> </textarea>
<input type="text" id="datum" name="datum" >
<input type="file" id="file" name="file" size="40" maxlength="100000">
<input type="button" value="speichern"
onclick="javascript:submitform()" />
</form>
<script>
function submitform(){
document.forms["myform"].submit();
}
</script>
和部分我的看法是這樣的:
anzeige=Anzeige(titel=request.POST['titel'],
anzeige=end_anzeige,
date=datetime.datetime.now(),
datum=request.POST['datum'],
file=request.FILES['file'])
anzeige.save()
我實際上正確提交,表單也應該像查詢其他查詢一樣在QueryDict中提交文件。有人能幫我弄清楚我在這裏失蹤的事嗎?
感謝
請問您可以提供Anzeige類的代碼及其保存方法嗎? –
我想,這不是關於儲蓄,問題是在保存之前,保存之前。 – doniyor
你爲什麼從帖子中刪除錯誤?除非您再次輸入,否則問題不完全清楚。無論如何,更好的方法是創建一個模型類和一個處理上傳的表單。如果您已經擁有它們,請提供代碼。 –