I am getting the below-mentioned error while executing the code:-
MultiValueDictKeyError at /count/ 'textbox' Request Method: GET Request URL: http://127.0.0.1:8000/count/ Django Version: 2.1 Exception Type: MultiValueDictKeyError Exception Value: 'textbox' Exception Location: /Users/rajans/anaconda3/lib/python3.7/site-packages/django/utils/datastructures.py in getitem, line 79 Python Executable: /Users/rajans/anaconda3/bin/python Python Version: 3.7.0 Python Path: ['/Users/rajans/Documents/djangoprojects/wordcount', '/Users/rajans/anaconda3/lib/python37.zip', '/Users/rajans/anaconda3/lib/python3.7', '/Users/rajans/anaconda3/lib/python3.7/lib-dynload', '/Users/rajans/anaconda3/lib/python3.7/site-packages', '/Users/rajans/anaconda3/lib/python3.7/site-packages/aeosa'] Server time: Tue, 5 Feb 2019 06:39:06 +0000
Python
from django.http import HttpResponse
from django.shortcuts import render
def homepage(request):
return render(request,'home.html')
def contact(request):
return HttpResponse("<h2> This is a contact_us page</h2><br> You can write to [email protected] for any query")
def count(request):
data=request.GET['textbox']
data_list=split(data)
data_len=len(data_list)
return render(request,'count.html',{'length':data_len})
--------
html form:-
<h1>Word Count</h1><br>
This is the home page for the Word count.
<form action="{% url 'count' name%}"> <!-- "{% url 'count' %}". this will load the url even if the path is changed..it will look for the name count-->
<textarea name="textbox" cols=40 rows="10"></textarea><br/>
<input type="submit" value="count"/>
</form>
count.html
<h1>Counted</h1><br/>
The length is :- {{length}}
data=request.GET.get('textbox')
– Ahtisham