I get the following error raise MultiValueDictKeyError(key) : django.utils.datastructures.MultiValueDictKeyError: 'redirect' when I try to save the value the user types in.
At first, I thought it had something to do with the input value, but since the error explicitly gives 'redirect' back I assume it has something to do with the redirect to the next part of the application. I have tried two different versions of return redirect, but it is very confusing what now exactly the right thing is.
At the same time, I get raise NoReverseMatch(msg) when I try to submit the input value to the database.
view
def InputData(request, element_id, session_id):
input_element = get_object_or_404(InputData_model, pk=element_id)
voice_service = input_element.service
session = lookup_or_create_session(voice_service, session_id)
if request.method == "POST":
session = get_object_or_404(CallSession, pk=session_id)
value = 'DTMF_input'
result = UserInput()
result.input_value = request.POST.get('input_value')
result.session = session
result.category = input_element.input_category
result.save()
return redirect(request.POST['redirect'])
template
<form id="input_form">
<property name="interdigittimeout" value="2s"/>
<property name="timeout" value="4s"/>
<property name="termchar" value="#" />
<field name="input_value" type="digits?minlength=1;maxlength=5">
<prompt>
<audio src="{{ ask_input_label }}"/>
</prompt>
<filled>
<assign name="redirect" expr="'{{ redirect_url }}'"/>
<submit next="{{ url }}" enctype="multipart/form-data" namelist="input_value" method="post"/>
<goto next="{{ redirect_url }}" />
</filled>
</field>
</form>
traceback
Internal Server Error: /vxml/InputData/33/57
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/datastructures.py", line 77, in __getitem__
list_ = super().__getitem__(key)
KeyError: 'redirect'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/vsdk/service_development/views/vse_input.py", line 55, in InputData
return redirect(request.POST['redirect'])
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/datastructures.py", line 79, in __getitem__
raise MultiValueDictKeyError(key)
django.utils.datastructures.MultiValueDictKeyError: 'redirect'
Internal Server Error: /vxml/InputData/33/57
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/datastructures.py", line 77, in __getitem__
list_ = super().__getitem__(key)
KeyError: 'redirect'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/vsdk/service_development/views/vse_input.py", line 55, in InputData
return redirect(request.POST['redirect'])
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/datastructures.py", line 79, in __getitem__
raise MultiValueDictKeyError(key)
django.utils.datastructures.MultiValueDictKeyError: 'redirect'
10.33.126.112 - - [29/Apr/2019:19:47:02 +0200] "POST /vxml/InputData/33/57 HTTP/1.1" 500 67237 "http://petrichor-rain-system.herokuapp.com/vxml/InputData/33/57" "Voxeo-VXML/16.0.4.5.89134"
Conclusion, I am completely confused with all the errors I get on this code and I don't know what to do anymore. Would someone want to help me make this work?
To help you understand these error traces, the usual way to look at them is this:
Search for the line(s) that refer to files that are part of your own code:
File "/app/vsdk/service_development/views/vse_input.py"File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py"or any line within thepython3.6/site-packagesfoldersIn this case there's only one line of your code, so that's easy. If there are multiple lines, the one most at the bottom is where to start.
Look at the location of the error:
line 55, in InputDatareturn redirect(request.POST['redirect'])That tells you exactly where the exception is raised
Look at the exception:
django.utils.datastructures.MultiValueDictKeyError: 'redirect'. This tells you more about what's wrong.KeyErrormeans the key doesn't exist in the dictionary. Here we have a special type of dictionary (keys can have multiple values). But basically the meaning is: this key ("redirect") doesn't exist, so I cannot access it.If you
print(request.POST.get('redirect'))you'll see it'sNone.