MultiValueDictKeyError at /insert/ 'fname'

Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/insert/

Django Version: 3.2.9
Python Version: 3.9.4
Installed Applications:
[‘django.contrib.admin’,
‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.messages’,
‘django.contrib.staticfiles’,
‘app’]
Installed Middleware:
[‘django.middleware.security.SecurityMiddleware’,
‘django.contrib.sessions.middleware.SessionMiddleware’,
‘django.middleware.common.CommonMiddleware’,
‘django.middleware.csrf.CsrfViewMiddleware’,
‘django.contrib.auth.middleware.AuthenticationMiddleware’,
‘django.contrib.messages.middleware.MessageMiddleware’,
‘django.middleware.clickjacking.XFrameOptionsMiddleware’]

Traceback (most recent call last):
File “X:\Django\CRUD\myvenv\lib\site-packages\django\utils\datastructures.py”, line 76, in getitem
list_ = super().getitem(key)

During handling of the above exception (‘fname’), another exception occurred:
File “X:\Django\CRUD\myvenv\lib\site-packages\django\core\handlers\exception.py”, line 47, in inner
response = get_response(request)
File “X:\Django\CRUD\myvenv\lib\site-packages\django\core\handlers\base.py”, line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “X:\Django\CRUD\app\views.py”, line 12, in InsertData
fname = request.POST[‘fname’]
File “X:\Django\CRUD\myvenv\lib\site-packages\django\utils\datastructures.py”, line 78, in getitem
raise MultiValueDictKeyError(key)

Exception Type: MultiValueDictKeyError at /insert/
Exception Value: ‘fname’

TRY THIS CODE

INSERT.HTML:-

HTML IN DJANGO

WELCOME TO THE DJANGO SESSION

THERE IS NOTHING WHICH CANNOT BE ACHIEVED

<center>

	<h1> HTML FORM</h1>
<form action="{% url 'insertdata' %}" method="post">
	{% csrf_token %}
	<table>
	<tr>

		<td>FIRSTNAME</td>
		<td><input type="text" name="fname"></td>	
	</tr>

	

	<tr>

		<td>LASTNAME</td>
		<td><input type="text" name="lname"></td>	
	</tr>
	


	<tr>

		<td>AGE</td>
		<td><input type="integer" name="age"></td>	
	</tr>


	<tr>

		<td>EMAIL</td>
		<td><input type="email" name="email"></td>	
	</tr>		


	<tr>
		<td><input type="submit" value="insert"></td>	
	</tr>
	</table>

</form>

</center>

VIEWS.PY:-

from django.shortcuts import render,redirect

from django.http import HttpResponse,HttpResponseNotFound

#http decorators

from django.views.decorators.http import require_http_methods
import datetime
from django.views import decorators
#for getting template

from django.template import loader

from .models import Employee

def Insertpage(request):
return render(request,‘app/insert.html’)

def insertdata(request):
if request.method==“POST”:

	firstname=request.POST['fname']
	lastname=request.POST['lname']
	Age=request.POST['age']
	EMail=request.POST['email']

	newuser=Employee.objects.create(first_name=firstname,last_name=lastname,age=Age,Email=EMail)

	return redirect('showpage')

def showpage(request):
all_data=Employee.objects.all()
return render(request,‘app/show.html’,{‘key1’:all_data})

URLS.PY;-

from django.urls import path,include
from . import views
from .views import *
urlpatterns = [
# path("",hello),
# path(“index/”,index),
# path(“a/”,notfound),
# path(“show/”,show),
# path(“view/”,view,name=“htmlform”),
path(“insert/”,Insertpage,name=“Insertpage”),
path(“insertdata/”,insertdata,name=“insertdata”),
path(“showpage/”,views.showpage,name=“showpage”),
]

MODELS.PY:-

from django.db import models

Create your models here.

class Employee(models.Model):
first_name=models.CharField(max_length=250)
last_name=models.CharField(max_length=250)
age=models.IntegerField()
Email=models.EmailField()