i am familiar with python and started to learn django and it is fun in the begining how ever a table insertion becomes nightmare to me from 2 days and always throwing the following error
sample() got an unexpected keyword argument 'firstname'
i have tried all the possible ways on documentation and stackoverflow but nothing works. but another view with same syntax got worked for me that's so weird. here are my files. this is my stack trace.
Traceback (most recent call last):
File "C:\Users\manee\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\manee\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\manee\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\manee\myapp\PE\views.py", line 77, in sample
a=sample(firstname=name)
Exception Type: TypeError at /sample
Exception Value: sample() got an unexpected keyword argument 'firstname'
this is the combination of the worked view and troubling view(problems is working fine,sample is not working).
def problems(request):
name=request.POST['name']
title=request.POST['title']
difficulty=request.POST['example']
description=request.POST['description']
solution=request.POST['solution']
code=request.POST['code']
question=problem(name=name,title=title,difficulty=difficulty,description=description,solution=solution,code=code)
question.save()
return render(request,'thanks.html')
def sample(request):
name=request.POST['name']
email=request.POST['email']
rno=request.POST['rno']
a=sample(firstname=name,email=email,rno=rno)
a.save()
return render(request,'example.html',{'name':name})
and here is my models.py
from django.db import models
#Create your models here.
class problem(models.Model):
id=models.AutoField(primary_key=True)
name=models.CharField(max_length=20)
title=models.CharField(max_length=30)
difficulty=models.CharField(max_length=10)
description=models.TextField()
solution=models.TextField()
code=models.TextField()
def __str__(self):
return self.name
class sample(models.Model):
firstname=models.CharField(max_length=20)
email=models.EmailField()
rno=models.IntegerField(primary_key=True)
def __str__(self):
return self.firstname
please get it fixed fast