我想知道如何解决'MultiValueDictKeyError'
下方的错误:
上传5个大图像文件时会发生这种情况。它有时只会发生。取决于图像文件的大小。例如:它有时适用于小图像文件。
HTML表格
<form enctype="multipart/form-data" action="/gallery/new/" method="post">
<input type='hidden' name='csrfmiddlewaretoken' value='2G9xCcnqFP47Z1c9RelOamnzv8g5l7pT' />
<p><label for="id_name">Name:</label> <input id="id_name" maxlength="256" name="name" type="text" /></p>
<p><label for="id_description">Description:</label> <textarea cols="40" id="id_description" name="description" rows="10">
</textarea></p>
<hr/>
<br />
<h1>Image Form</h1>
<div id="image_formset">
<h3>Image 1</h3>
<label for="image_name_1">Name:</label>
<input id="image_name_1" maxlength="256" name="image_name_1" type="text" />
<label for="image_description_1">Description:</label>
<textarea id="image_description_1" name="image_description_1" rows="7"></textarea>
<label for="image_file_one">Image file:</label>
<input type="file" id="image_file_one" name="image_file_one" title="image"/>
<hr/>
<h3>Image 2</h3>
<label for="image_name_2">Name:</label>
<input id="image_name_2" maxlength="256" name="image_name_2" type="text" />
<label for="image_description_2">Description:</label>
<textarea id="image_description_2" name="image_description_2" rows="7"></textarea>
<label for="image_file_two">Image file:</label>
<input type="file" id="image_file_two" name="image_file_two" title="image"/>
<hr/>
<h3>Image 3</h3>
<label for="image_name_3">Name:</label>
<input id="image_name_3" maxlength="256" name="image_name_3" type="text" />
<label for="image_description_3">Description:</label>
<textarea id="image_description_3" name="image_description_3" rows="7"></textarea>
<label for="image_file_three">Image file:</label>
<input type="file" id="image_file_three" name="image_file_three" title="image"/>
<hr/>
<h3>Image 4</h3>
<label for="image_name_4">Name:</label>
<input id="image_name_4" maxlength="256" name="image_name_4" type="text" />
<label for="image_description_4">Description:</label>
<textarea id="image_description_4" name="image_description_4" rows="7"></textarea>
<label for="image_file_four">Image file:</label>
<input type="file" id="image_file_four" name="image_file_four" title="image"/>
<hr/>
<h3>Image 5</h3>
<label for="image_name_5">Name:</label>
<input id="image_name_5" maxlength="256" name="image_name_5" type="text" />
<label for="image_description_5">Description:</label>
<textarea id="image_description_5" name="image_description_5" rows="7"></textarea>
<label for="image_file_five">Image file:</label>
<input type="file" id="image_file_five" name="image_file_five" title="image"/>
<hr/>
</div>
<div><input type="submit" value="Submit"/></div>
</form>
错误日志:
MultiValueDictKeyError at /gallery/new/
"'image_file_one'"
Request Method: POST
Request URL: http://127.0.0.1:8000/gallery/new/
Django Version: 1.6.5
Exception Type: MultiValueDictKeyError
Exception Value:
"'image_file_one'"
Exception Location: /opt/Documents/project_name/coolsite/projects/cms/django/utils/datastructures.py in __getitem__, line 301
Python Executable: /usr/bin/python
Python Version: 2.7.6
Python Path:
['lib',
'/opt/Documents/project_name/coolsite/projects/cms',
'/opt/Documents/project_name/coolsite/projects/cms/djangoappengine/lib',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.1.1',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/antlr3',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/fancy_urllib',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/ipaddr',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/yaml-3.10',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/rsa',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/pyasn1',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/pyasn1_modules',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/simplejson',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/endpoints-1.0',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/jinja2-2.6',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/protorpc-1.0',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/PyAMF-0.6.1',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/markupsafe-0.15',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2',
'lib',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
'/Library/Python/2.7/site-packages']
Server time: Thu, 11 Dec 2014 20:39:49 +0000
答案 0 :(得分:0)
在settings.py
增加以下值后,它可以正常工作FILE_UPLOAD_MAX_MEMORY_SIZE = 35000000
显然,此值适用于POST中所有文件的总大小。 例如:它允许5个文件,每个文件的最大大小为7 MB。或4个文件,每个8.75 MB,依此类推。