问题描述:

Why do I get MultiValueDictKeyError?

Here is the minimized project:

forms.py

from django.core.context_processors import csrf

from django.http import HttpResponseRedirect

from django.shortcuts import render_to_response

from djangobug.forms import PForm

def pview(request):

if request.POST:

form = PForm(request.POST)

if form.is_valid():

form.save()

return HttpResponseRedirect('/')

else:

form = PForm()

args = {}

args.update(csrf(request))

args['form'] = form

return render_to_response('pview.html', args)

models.py

coding: utf-8

from django.db import models

class P(models.Model):

n = models.CharField(max_length=255)

class I(models.Model):

t = models.CharField(max_length=255)

p = models.ManyToManyField(P)

urls.py

from django.conf.urls import patterns, url

from djangobug import views

urlpatterns = patterns('',

url(r'^$', views.pview),

)

views.py

from django.core.context_processors import csrf

from django.shortcuts import render_to_response

from djangobug.forms import PForm

from django.core.context_processors import csrf

from django.http import HttpResponseRedirect

from django.shortcuts import render_to_response

from djangobug.forms import PForm

def pview(request):

if request.POST:

form = PForm(request.POST)

if form.is_valid():

form.save()

return HttpResponseRedirect('/')

else:

form = PForm()

args = {}

args.update(csrf(request))

args['form'] = form

return render_to_response('pview.html', args)

pview.html

<!DOCTYPE html>

<html>

<head lang="en">

<meta charset="UTF-8">

<title></title>

</head>

<body>

</body>

</html>

<form action="" method="post">

{% csrf_token %}

<ul>

{{ form.as_ul }}

</ul>

<input type="submit" name="submit" value="Submit" />

</form>

</body>

</html>

Error:

MultiValueDictKeyError at /

"'p'"

Request Method: POST

Request URL: http://127.0.0.1:8000/

Django Version: 1.7.1

Exception Type: MultiValueDictKeyError

Exception Value:

"'p'"

Exception Location: /usr/local/lib/python2.7/dist-packages/django/utils/datastructures.py in __getitem__, line 319

Python Executable: /usr/bin/python2.7

Python Version: 2.7.6

Python Path:

['/home/user/src/djangobug',

'/home/user/Installed/pycharm-3.4.1/helpers/pydev',

'/usr/local/lib/python2.7/dist-packages/Trac-1.0.2-py2.7.egg',

'/usr/lib/python2.7/dist-packages',

'/usr/local/lib/python2.7/dist-packages/pudb-2014.1-py2.7.egg',

'/usr/local/lib/python2.7/dist-packages/urwid-1.3.0-py2.7-linux-x86_64.egg',

'/home/user/src/djangobug',

'/usr/lib/python2.7',

'/usr/lib/python2.7/plat-x86_64-linux-gnu',

'/usr/lib/python2.7/lib-tk',

'/usr/lib/python2.7/lib-old',

'/usr/lib/python2.7/lib-dynload',

'/usr/local/lib/python2.7/dist-packages',

'/usr/lib/python2.7/dist-packages/PILcompat',

'/usr/lib/python2.7/dist-packages/gtk-2.0',

'/usr/lib/pymodules/python2.7',

'/usr/lib/python2.7/dist-packages/ubuntu-sso-client']

Server time: Tue, 18 Nov 2014 00:47:25 +0000

Traceback Switch to copy-and-paste view

/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py in get_response

response = middleware_method(request, callback, callback_args, callback_kwargs)

if response:

break

if response is None:

wrapped_callback = self.make_view_atomic(callback)

try:

response = wrapped_callback(request, *callback_args, **callback_kwargs)

...

except Exception as e:

# If the view raised an exception, run it through exception

# middleware, and if the exception middleware returns a

# response, use that. Otherwise, reraise the exception.

for middleware_method in self._exception_middleware:

response = middleware_method(request, e)

▶ Local vars

Variable Value

e

MultiValueDictKeyError("'p'",)

resolver_match

ResolverMatch(func=<function pview at 0x7fb330e89f50>, args=(), kwargs={}, url_name='djangobug.views.pview', app_name='None', namespace='')

callback_args

()

middleware_method

<bound method CsrfViewMiddleware.process_view of <django.middleware.csrf.CsrfViewMiddleware object at 0x7fb33058aa50>>

self

<django.core.handlers.wsgi.WSGIHandler object at 0x7fb3315e5790>

request

"<WSGIRequest\npath:/,\nGET:<QueryDict: {}>,\nPOST:<QueryDict: {u'csrfmiddlewaretoken': [u'JOrHIfS1xWFzLkH2aSdF8UsQ7m5RiqI8'], u't': [u'aa'], u'submit': [u'Submit']}>,\nCOOKIES:{'csrftoken': 'JOrHIfS1xWFzLkH2aSdF8UsQ7m5RiqI8'},\nMETA:{'CLASSPATH': '/home/user/Installed/pycharm-3.4.1/bin/../lib/bootstrap.jar:/home/user/Installed/pycharm-3.4.1/bin/../lib/extensions.jar:/home/user/Installed/pycharm-3.4.1/bin/../lib/util.jar:/home/user/Installed/pycharm-3.4.1/bin/../lib/jdom.jar:/home/user/Installed/pycharm-3.4.1/bin/../lib/log4j.jar:/home/user/Installed/pycharm-3.4.1/bin/../lib/trove4j.jar:/home/user/Installed/pycharm-3.4.1/bin/../lib/jna.jar',\n 'CLUTTER_IM_MODULE': 'xim',\n 'COLORTERM': 'xfce4-terminal',\n 'CONTENT_LENGTH': '71',\n 'CONTENT_TYPE': 'application/x-www-form-urlencoded',\n 'CRASH_HOME': '/home/user/.gvm/crash/current',\n u'CSRF_COOKIE': u'JOrHIfS1xWFzLkH2aSdF8UsQ7m5RiqI8',\n 'DBUS_SESSION_BUS_ADDRESS': 'unix:abstract=/tmp/dbus-BaBGk05MeI',\n 'DEFAULTS_PATH': '/usr/share/gconf/xubuntu.default.path',\n 'DESKTOP_SESSION': 'xubuntu',\n 'DISPLAY': ':0.0',\n 'DJANGO_SETTINGS_MODULE': 'djangobug.settings',\n 'GAIDEN_HOME': '/home/user/.gvm/gaiden/current',\n 'GATEWAY_INTERFACE': 'CGI/1.1',\n 'GDMSESSION': 'xubuntu',\n 'GDM_LANG': 'en_GB',\n 'GLADE_CATALOG_PATH': ':',\n 'GLADE_MODULE_PATH': ':',\n 'GLADE_PIXMAP_PATH': ':',\n 'GLIDE_HOME': '/home/user/.gvm/glide/current',\n 'GNOME_KEYRING_CONTROL': '/run/user/1000/keyring-CJD9Qf',\n 'GNOME_KEYRING_PID': '2363',\n 'GPG_AGENT_INFO': '/run/user/1000/keyring-CJD9Qf/gpg:0:1',\n 'GRADLE_HOME': '/home/user/.gvm/gradle/current',\n 'GRAILS_HOME': '/home/user/.gvm/grails/current',\n 'GRIFFON_HOME': '/home/user/.gvm/griffon/current',\n 'GROOVYSERV_HOME': '/home/user/.gvm/groovyserv/current',\n 'GROOVY_HOME': '/home/user/.gvm/groovy/current',\n 'GTK_IM_MODULE': 'ibus',\n 'GTK_MODULES': 'overlay-scrollbar',\n 'GVM_BROADCAST_SERVICE': 'http://cast.gvm.io',\n 'GVM_BROKER_SERVICE': 'http://release.gvm.io',\n 'GVM_DIR': '/home/user/.gvm',\n 'GVM_INIT': 'true',\n 'GVM_PLATFORM': 'Linux',\n 'GVM_SERVICE': 'http://api.gvmtool.net',\n 'GVM_VERSION': '2.2.0',\n 'HOME': '/home/user',\n 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',\n 'HTTP_ACCEPT_ENCODING': 'gzip, deflate',\n 'HTTP_ACCEPT_LANGUAGE': 'en-GB,en;q=0.5',\n 'HTTP_CONNECTION': 'keep-alive',\n 'HTTP_COOKIE': 'csrftoken=JOrHIfS1xWFzLkH2aSdF8UsQ7m5RiqI8',\n 'HTTP_HOST': '127.0.0.1:8000',\n 'HTTP_REFERER': 'http://127.0.0.1:8000/',\n 'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0',\n 'IM_CONFIG_PHASE': '1',\n 'INSTANCE': '',\n 'JAVA_HOME': '/usr/lib/jvm/java-7-openjdk-amd64',\n 'JBAKE_HOME': '/home/user/.gvm/jbake/current',\n 'JOB': 'dbus',\n 'LANG': 'en_GB.UTF-8',\n 'LANGUAGE': 'en_GB:en',\n 'LAZYBONES_HOME': '/home/user/.gvm/lazybones/current',\n 'LC_ADDRESS': 'en_GB.UTF-8',\n 'LC_IDENTIFICATION': 'en_GB.UTF-8',\n 'LC_MEASUREMENT': 'en_GB.UTF-8',\n 'LC_MONETARY': 'en_GB.UTF-8',\n 'LC_NAME': 'en_GB.UTF-8',\n 'LC_NUMERIC': 'en_GB.UTF-8',\n 'LC_PAPER': 'en_GB.UTF-8',\n 'LC_TELEPHONE': 'en_GB.UTF-8',\n 'LC_TIME': 'en_GB.UTF-8',\n 'LD_LIBRARY_PATH': '/home/user/Installed/pycharm-3.4.1/bin:',\n 'LESSCLOSE': '/usr/bin/lesspipe %s %s',\n 'LESSOPEN': '| /usr/bin/lesspipe %s',\n 'LOGNAME': 'user',\n 'LS_COLORS': 'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:',\n 'MANDATORY_PATH': '/usr/share/gconf/xubuntu.mandatory.path',\n 'PAPERSIZE': 'a4',\n 'PATH': '/home/user/.gvm/vertx/current/bin:/home/user/.gvm/springboot/current/bin:/home/user/.gvm/lazybones/current/bin:/home/user/.gvm/jbake/current/bin:/home/user/.gvm/groovyserv/current/bin:/home/user/.gvm/groovy/current/bin:/home/user/.gvm/griffon/current/bin:/home/user/.gvm/grails/current/bin:/home/user/.gvm/gradle/current/bin:/home/user/.gvm/glide/current/bin:/home/user/.gvm/gaiden/current/bin:/home/user/.gvm/crash/current/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-7-openjdk-amd64/bin:/home/user/Installed/activator-1.2.10-minimal',\n 'PATH_INFO': u'/',\n 'PWD': '/home/user',\n 'PYCHARM_HOSTED': '1',\n 'PYTHONIOENCODING': 'UTF-8',\n 'PYTHONPATH': '/home/user/src/djangobug',\n 'PYTHONUNBUFFERED': '1',\n 'QT4_IM_MODULE': 'xim',\n 'QT_IM_MODULE': 'ibus',\n 'QT_QPA_PLATFORMTHEME': 'appmenu-qt5',\n 'QUERY_STRING': '',\n 'REMOTE_ADDR': '127.0.0.1',\n 'REMOTE_HOST': '',\n 'REQUEST_METHOD': 'POST',\n 'RUN_MAIN': 'true',\n 'SCRIPT_NAME': u'',\n 'SELINUX_INIT': 'YES',\n 'SERVER_NAME': 'localhost',\n 'SERVER_PORT': '8000',\n 'SERVER_PROTOCOL': 'HTTP/1.1',\n 'SERVER_SOFTWARE': 'WSGIServer/0.1 Python/2.7.6',\n 'SESSION': 'xubuntu',\n 'SESSIONTYPE': '',\n 'SESSION_MANAGER': 'local/ThinkPad:@/tmp/.ICE-unix/2587,unix/ThinkPad:/tmp/.ICE-unix/2587',\n 'SHELL': '/bin/bash',\n 'SHLVL': '1',\n 'SPRINGBOOT_HOME': '/home/user/.gvm/springboot/current',\n 'SSH_AUTH_SOCK': '/run/user/1000/keyring-CJD9Qf/ssh',\n 'TERM': 'emacs',\n 'TEXTDOMAIN': 'im-config',\n 'TEXTDOMAINDIR': '/usr/share/locale/',\n 'TZ': 'UTC',\n 'UPSTART_EVENTS': 'started xsession',\n 'UPSTART_INSTANCE': '',\n 'UPSTART_JOB': 'startxfce4',\n 'UPSTART_SESSION': 'unix:abstract=/com/ubuntu/upstart-session/1000/2370',\n 'USER': 'user',\n 'VERTX_HOME': '/home/user/.gvm/vertx/current',\n 'WINDOWID': '92276799',\n 'XAUTHORITY': '/home/user/.Xauthority',\n 'XDG_CONFIG_DIRS': '/etc/xdg/xdg-xubuntu:/usr/share/upstart/xdg:/etc/xdg:/etc/xdg',\n 'XDG_CURRENT_DESKTOP': 'XFCE',\n 'XDG_DATA_DIRS': '/usr/share/xubuntu:/usr/share/xfce4:/usr/local/share/:/usr/share/:/usr/share',\n 'XDG_GREETER_DATA_DIR': '/var/lib/lightdm-data/user',\n 'XDG_MENU_PREFIX': 'xfce-',\n 'XDG_RUNTIME_DIR': '/run/user/1000',\n 'XDG_SEAT': 'seat0',\n 'XDG_SEAT_PATH': '/org/freedesktop/DisplayManager/Seat0',\n 'XDG_SESSION_ID': 'c2',\n 'XDG_SESSION_PATH': '/org/freedesktop/DisplayManager/Session0',\n 'XDG_VTNR': '7',\n 'XMODIFIERS': '@im=ibus',\n '_': '/home/user/Installed/pycharm-3.4.1/bin/pycharm.sh',\n 'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7fb336cf21e0>,\n 'wsgi.file_wrapper': <class wsgiref.util.FileWrapper at 0x7fb331472bb0>,\n 'wsgi.input': <socket._fileobject object at 0x7fb3305a0650>,\n 'wsgi.multiprocess': False,\n 'wsgi.multithread': True,\n 'wsgi.run_once': False,\n 'wsgi.url_scheme': 'http',\n 'wsgi.version': (1, 0)}>"

callback

<function pview at 0x7fb330e89f50>

wrapped_callback

<function pview at 0x7fb330e89f50>

resolver

<RegexURLResolver 'djangobug.urls' (None:None) ^/>

callback_kwargs

{}

response

None

urlconf

'djangobug.urls'

/home/user/src/djangobug/djangobug/views.py in pview

from djangobug.forms import PForm

def pview(request):

if request.POST:

form = PForm(request.POST)

if form.is_valid():

form.save()

...

return HttpResponseRedirect('/')

else:

form = PForm()

args = {}

args.update(csrf(request))

args['form'] = form

▶ Local vars

Variable Value

request

"<WSGIRequest\npath:/,\nGET:<QueryDict: {}>,\nPOST:<QueryDict: {u'csrfmiddlewaretoken': [u'JOrHIfS1xWFzLkH2aSdF8UsQ7m5RiqI8'], u't': [u'aa'], u'submit': [u'Submit']}>,\nCOOKIES:{'csrftoken': 'JOrHIfS1xWFzLkH2aSdF8UsQ7m5RiqI8'},\nMETA:{'CLASSPATH': '/home/user/Installed/pycharm-3.4.1/bin/../lib/bootstrap.jar:/home/user/Installed/pycharm-3.4.1/bin/../lib/extensions.jar:/home/user/Installed/pycharm-3.4.1/bin/../lib/util.jar:/home/user/Installed/pycharm-3.4.1/bin/../lib/jdom.jar:/home/user/Installed/pycharm-3.4.1/bin/../lib/log4j.jar:/home/user/Installed/pycharm-3.4.1/bin/../lib/trove4j.jar:/home/user/Installed/pycharm-3.4.1/bin/../lib/jna.jar',\n 'CLUTTER_IM_MODULE': 'xim',\n 'COLORTERM': 'xfce4-terminal',\n 'CONTENT_LENGTH': '71',\n 'CONTENT_TYPE': 'application/x-www-form-urlencoded',\n 'CRASH_HOME': '/home/user/.gvm/crash/current',\n u'CSRF_COOKIE': u'JOrHIfS1xWFzLkH2aSdF8UsQ7m5RiqI8',\n 'DBUS_SESSION_BUS_ADDRESS': 'unix:abstract=/tmp/dbus-BaBGk05MeI',\n 'DEFAULTS_PATH': '/usr/share/gconf/xubuntu.default.path',\n 'DESKTOP_SESSION': 'xubuntu',\n 'DISPLAY': ':0.0',\n 'DJANGO_SETTINGS_MODULE': 'djangobug.settings',\n 'GAIDEN_HOME': '/home/user/.gvm/gaiden/current',\n 'GATEWAY_INTERFACE': 'CGI/1.1',\n 'GDMSESSION': 'xubuntu',\n 'GDM_LANG': 'en_GB',\n 'GLADE_CATALOG_PATH': ':',\n 'GLADE_MODULE_PATH': ':',\n 'GLADE_PIXMAP_PATH': ':',\n 'GLIDE_HOME': '/home/user/.gvm/glide/current',\n 'GNOME_KEYRING_CONTROL': '/run/user/1000/keyring-CJD9Qf',\n 'GNOME_KEYRING_PID': '2363',\n 'GPG_AGENT_INFO': '/run/user/1000/keyring-CJD9Qf/gpg:0:1',\n 'GRADLE_HOME': '/home/user/.gvm/gradle/current',\n 'GRAILS_HOME': '/home/user/.gvm/grails/current',\n 'GRIFFON_HOME': '/home/user/.gvm/griffon/current',\n 'GROOVYSERV_HOME': '/home/user/.gvm/groovyserv/current',\n 'GROOVY_HOME': '/home/user/.gvm/groovy/current',\n 'GTK_IM_MODULE': 'ibus',\n 'GTK_MODULES': 'overlay-scrollbar',\n 'GVM_BROADCAST_SERVICE': 'http://cast.gvm.io',\n 'GVM_BROKER_SERVICE': 'http://release.gvm.io',\n 'GVM_DIR': '/home/user/.gvm',\n 'GVM_INIT': 'true',\n 'GVM_PLATFORM': 'Linux',\n 'GVM_SERVICE': 'http://api.gvmtool.net',\n 'GVM_VERSION': '2.2.0',\n 'HOME': '/home/user',\n 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',\n 'HTTP_ACCEPT_ENCODING': 'gzip, deflate',\n 'HTTP_ACCEPT_LANGUAGE': 'en-GB,en;q=0.5',\n 'HTTP_CONNECTION': 'keep-alive',\n 'HTTP_COOKIE': 'csrftoken=JOrHIfS1xWFzLkH2aSdF8UsQ7m5RiqI8',\n 'HTTP_HOST': '127.0.0.1:8000',\n 'HTTP_REFERER': 'http://127.0.0.1:8000/',\n 'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0',\n 'IM_CONFIG_PHASE': '1',\n 'INSTANCE': '',\n 'JAVA_HOME': '/usr/lib/jvm/java-7-openjdk-amd64',\n 'JBAKE_HOME': '/home/user/.gvm/jbake/current',\n 'JOB': 'dbus',\n 'LANG': 'en_GB.UTF-8',\n 'LANGUAGE': 'en_GB:en',\n 'LAZYBONES_HOME': '/home/user/.gvm/lazybones/current',\n 'LC_ADDRESS': 'en_GB.UTF-8',\n 'LC_IDENTIFICATION': 'en_GB.UTF-8',\n 'LC_MEASUREMENT': 'en_GB.UTF-8',\n 'LC_MONETARY': 'en_GB.UTF-8',\n 'LC_NAME': 'en_GB.UTF-8',\n 'LC_NUMERIC': 'en_GB.UTF-8',\n 'LC_PAPER': 'en_GB.UTF-8',\n 'LC_TELEPHONE': 'en_GB.UTF-8',\n 'LC_TIME': 'en_GB.UTF-8',\n 'LD_LIBRARY_PATH': '/home/user/Installed/pycharm-3.4.1/bin:',\n 'LESSCLOSE': '/usr/bin/lesspipe %s %s',\n 'LESSOPEN': '| /usr/bin/lesspipe %s',\n 'LOGNAME': 'user',\n 'LS_COLORS': 'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:',\n 'MANDATORY_PATH': '/usr/share/gconf/xubuntu.mandatory.path',\n 'PAPERSIZE': 'a4',\n 'PATH': '/home/user/.gvm/vertx/current/bin:/home/user/.gvm/springboot/current/bin:/home/user/.gvm/lazybones/current/bin:/home/user/.gvm/jbake/current/bin:/home/user/.gvm/groovyserv/current/bin:/home/user/.gvm/groovy/current/bin:/home/user/.gvm/griffon/current/bin:/home/user/.gvm/grails/current/bin:/home/user/.gvm/gradle/current/bin:/home/user/.gvm/glide/current/bin:/home/user/.gvm/gaiden/current/bin:/home/user/.gvm/crash/current/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-7-openjdk-amd64/bin:/home/user/Installed/activator-1.2.10-minimal',\n 'PATH_INFO': u'/',\n 'PWD': '/home/user',\n 'PYCHARM_HOSTED': '1',\n 'PYTHONIOENCODING': 'UTF-8',\n 'PYTHONPATH': '/home/user/src/djangobug',\n 'PYTHONUNBUFFERED': '1',\n 'QT4_IM_MODULE': 'xim',\n 'QT_IM_MODULE': 'ibus',\n 'QT_QPA_PLATFORMTHEME': 'appmenu-qt5',\n 'QUERY_STRING': '',\n 'REMOTE_ADDR': '127.0.0.1',\n 'REMOTE_HOST': '',\n 'REQUEST_METHOD': 'POST',\n 'RUN_MAIN': 'true',\n 'SCRIPT_NAME': u'',\n 'SELINUX_INIT': 'YES',\n 'SERVER_NAME': 'localhost',\n 'SERVER_PORT': '8000',\n 'SERVER_PROTOCOL': 'HTTP/1.1',\n 'SERVER_SOFTWARE': 'WSGIServer/0.1 Python/2.7.6',\n 'SESSION': 'xubuntu',\n 'SESSIONTYPE': '',\n 'SESSION_MANAGER': 'local/ThinkPad:@/tmp/.ICE-unix/2587,unix/ThinkPad:/tmp/.ICE-unix/2587',\n 'SHELL': '/bin/bash',\n 'SHLVL': '1',\n 'SPRINGBOOT_HOME': '/home/user/.gvm/springboot/current',\n 'SSH_AUTH_SOCK': '/run/user/1000/keyring-CJD9Qf/ssh',\n 'TERM': 'emacs',\n 'TEXTDOMAIN': 'im-config',\n 'TEXTDOMAINDIR': '/usr/share/locale/',\n 'TZ': 'UTC',\n 'UPSTART_EVENTS': 'started xsession',\n 'UPSTART_INSTANCE': '',\n 'UPSTART_JOB': 'startxfce4',\n 'UPSTART_SESSION': 'unix:abstract=/com/ubuntu/upstart-session/1000/2370',\n 'USER': 'user',\n 'VERTX_HOME': '/home/user/.gvm/vertx/current',\n 'WINDOWID': '92276799',\n 'XAUTHORITY': '/home/user/.Xauthority',\n 'XDG_CONFIG_DIRS': '/etc/xdg/xdg-xubuntu:/usr/share/upstart/xdg:/etc/xdg:/etc/xdg',\n 'XDG_CURRENT_DESKTOP': 'XFCE',\n 'XDG_DATA_DIRS': '/usr/share/xubuntu:/usr/share/xfce4:/usr/local/share/:/usr/share/:/usr/share',\n 'XDG_GREETER_DATA_DIR': '/var/lib/lightdm-data/user',\n 'XDG_MENU_PREFIX': 'xfce-',\n 'XDG_RUNTIME_DIR': '/run/user/1000',\n 'XDG_SEAT': 'seat0',\n 'XDG_SEAT_PATH': '/org/freedesktop/DisplayManager/Seat0',\n 'XDG_SESSION_ID': 'c2',\n 'XDG_SESSION_PATH': '/org/freedesktop/DisplayManager/Session0',\n 'XDG_VTNR': '7',\n 'XMODIFIERS': '@im=ibus',\n '_': '/home/user/Installed/pycharm-3.4.1/bin/pycharm.sh',\n 'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7fb336cf21e0>,\n 'wsgi.file_wrapper': <class wsgiref.util.FileWrapper at 0x7fb331472bb0>,\n 'wsgi.input': <socket._fileobject object at 0x7fb3305a0650>,\n 'wsgi.multiprocess': False,\n 'wsgi.multithread': True,\n 'wsgi.run_once': False,\n 'wsgi.url_scheme': 'http',\n 'wsgi.version': (1, 0)}>"

form

<djangobug.forms.PForm object at 0x7fb3302fff90>

/home/user/src/djangobug/djangobug/forms.py in save

class PForm(forms.Form):

t = forms.CharField(max_length=255, required=True, widget=forms.TextInput())

p = forms.ModelMultipleChoiceField(queryset=P.objects.all().order_by('n'), required=False, widget=forms.SelectMultiple())

def save(self):

i = I.objects.create(

t = self.data['t'],

p = self.data['p'],

...

)

i.save()

▶ Local vars

Variable Value

self

<djangobug.forms.PForm object at 0x7fb3302fff90>

/usr/local/lib/python2.7/dist-packages/django/utils/datastructures.py in __getitem__

"""

Returns the last data value for this key, or [] if it's an empty list;

raises KeyError if not found.

"""

try:

list_ = super(MultiValueDict, self).__getitem__(key)

except KeyError:

raise MultiValueDictKeyError(repr(key))

...

try:

return list_[-1]

except IndexError:

return []

def __setitem__(self, key, value):

▶ Local vars

Variable Value

self

<QueryDict: {u'csrfmiddlewaretoken': [u'JOrHIfS1xWFzLkH2aSdF8UsQ7m5RiqI8'], u't': [u'aa'], u'submit': [u'Submit']}>

key

'p'

Environment: Request Method: POST Request URL: http://127.0.0.1:8000/ Django Version: 1.7.1 Python Version: 2.7.6 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'djangobug') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware') Traceback: File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response 111. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/user/src/djangobug/djangobug/views.py" in pview 11. form.save() File "/home/user/src/djangobug/djangobug/forms.py" in save 11. p = self.data['p'], File "/usr/local/lib/python2.7/dist-packages/django/utils/datastructures.py" in __getitem__ 319. raise MultiValueDictKeyError(repr(key)) Exception Type: MultiValueDictKeyError at / Exception Value: "'p'"

Request information

GET

No GET data

POST

Variable Value

csrfmiddlewaretoken

u'JOrHIfS1xWFzLkH2aSdF8UsQ7m5RiqI8'

t

u'aa'

submit

u'Submit'

FILES

No FILES data

COOKIES

Variable Value

csrftoken

'JOrHIfS1xWFzLkH2aSdF8UsQ7m5RiqI8'

META

Variable Value

RUN_MAIN

'true'

HTTP_REFERER

'http://127.0.0.1:8000/'

XDG_GREETER_DATA_DIR

'/var/lib/lightdm-data/user'

QT4_IM_MODULE

'xim'

SERVER_SOFTWARE

'WSGIServer/0.1 Python/2.7.6'

UPSTART_EVENTS

'started xsession'

SCRIPT_NAME

u''

REQUEST_METHOD

'POST'

GVM_PLATFORM

'Linux'

SERVER_PROTOCOL

'HTTP/1.1'

LC_PAPER

'en_GB.UTF-8'

HOME

'/home/user'

DISPLAY

':0.0'

GVM_BROKER_SERVICE

'http://release.gvm.io'

LANG

'en_GB.UTF-8'

SHELL

'/bin/bash'

XDG_DATA_DIRS

'/usr/share/xubuntu:/usr/share/xfce4:/usr/local/share/:/usr/share/:/usr/share'

MANDATORY_PATH

'/usr/share/gconf/xubuntu.mandatory.path'

GVM_INIT

'true'

TEXTDOMAIN

'im-config'

UPSTART_INSTANCE

''

JOB

'dbus'

SESSION

'xubuntu'

LAZYBONES_HOME

'/home/user/.gvm/lazybones/current'

SERVER_PORT

'8000'

XMODIFIERS

'@im=ibus'

JAVA_HOME

'/usr/lib/jvm/java-7-openjdk-amd64'

SELINUX_INIT

'YES'

PATH_INFO

u'/'

XDG_RUNTIME_DIR

'/run/user/1000'

GTK_IM_MODULE

'ibus'

LC_ADDRESS

'en_GB.UTF-8'

PYTHONPATH

'/home/user/src/djangobug'

GROOVY_HOME

'/home/user/.gvm/groovy/current'

GVM_SERVICE

'http://api.gvmtool.net'

HTTP_HOST

'127.0.0.1:8000'

GNOME_KEYRING_PID

'2363'

wsgi.version

(1, 0)

XDG_CURRENT_DESKTOP

'XFCE'

XDG_SESSION_ID

'c2'

DBUS_SESSION_BUS_ADDRESS

'unix:abstract=/tmp/dbus-BaBGk05MeI'

GTK_MODULES

'overlay-scrollbar'

HTTP_ACCEPT

'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'

DESKTOP_SESSION

'xubuntu'

CRASH_HOME

'/home/user/.gvm/crash/current'

LESSCLOSE

'/usr/bin/lesspipe %s %s'

DEFAULTS_PATH

'/usr/share/gconf/xubuntu.default.path'

wsgi.run_once

False

wsgi.errors

<open file '<stderr>', mode 'w' at 0x7fb336cf21e0>

wsgi.multiprocess

False

HTTP_ACCEPT_LANGUAGE

'en-GB,en;q=0.5'

VERTX_HOME

'/home/user/.gvm/vertx/current'

PYCHARM_HOSTED

'1'

GVM_DIR

'/home/user/.gvm'

PAPERSIZE

'a4'

INSTANCE

''

wsgi.input

<socket._fileobject object at 0x7fb3305a0650>

LC_NAME

'en_GB.UTF-8'

XDG_MENU_PREFIX

'xfce-'

GROOVYSERV_HOME

'/home/user/.gvm/groovyserv/current'

GRAILS_HOME

'/home/user/.gvm/grails/current'

XDG_SEAT

'seat0'

LC_NUMERIC

'en_GB.UTF-8'

GAIDEN_HOME

'/home/user/.gvm/gaiden/current'

GLADE_PIXMAP_PATH

':'

HTTP_COOKIE

'csrftoken=JOrHIfS1xWFzLkH2aSdF8UsQ7m5RiqI8'

LESSOPEN

'| /usr/bin/lesspipe %s'

QUERY_STRING

''

QT_IM_MODULE

'ibus'

IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII

网友答案:

The error occurs in forms.py which source you did not supply. I believe that you can fix it by changing data to cleaned_data in your form code.

t = self.cleaned_data['t']
p = self.cleaned_data['p']

etc.

相关阅读:
Top