get() missing 1 required positional argument: 'id'

6,101 views
Skip to first unread message

Adya Mit

unread,
Jun 17, 2020, 12:09:06 AM6/17/20
to Django users
did not work

views.py
class EmployeeCBV(View):
def get(self,request,id,*args,**kwargs):
emp=Employee.objects.get(id=id)
json_data=serialize('json',[emp,])

         return HttpResponse(json_data,content_type='application/json')

urls.py
from django.contrib import admin
from django.urls import path
from testapp import views

urlpatterns = [
path('admin/', admin.site.urls),
path('home/',views.EmployeeCBV.as_view(),name='home'),

]
result:

TypeError at /home/

get() missing 1 required positional argument: 'id'
Request Method: GET
Request URL: http://127.0.0.1:8000/home/
Django Version: 3.0.6
Exception Type: TypeError
Exception Value:
get() missing 1 required positional argument: 'id'
Exception Location: C:\Users\adyam\AppData\Local\Programs\Python\Python37\lib\site-packages\django\views\generic\base.py in dispatch, line 97
Python Executable: C:\Users\adyam\AppData\Local\Programs\Python\Python37\python.exe
Python Version: 3.7.5
Python Path:
['C:\\Users\\adyam\\PycharmProjects\\RestApi1\\withoutrestm',
 'C:\\Users\\adyam\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip',
 'C:\\Users\\adyam\\AppData\\Local\\Programs\\Python\\Python37\\DLLs',
 'C:\\Users\\adyam\\AppData\\Local\\Programs\\Python\\Python37\\lib',
 'C:\\Users\\adyam\\AppData\\Local\\Programs\\Python\\Python37',
 'C:\\Users\\adyam\\AppData\\Roaming\\Python\\Python37\\site-packages',
 'C:\\Users\\adyam\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages']
Server time: Wed, 17 Jun 2020 04:05:09 +0000

meera gangani

unread,
Jun 17, 2020, 12:19:17 AM6/17/20
to django...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/00451532-6e7f-433a-a21b-d8c5e2afecf6o%40googlegroups.com.

MUGOYA DIHFAHSIH

unread,
Jun 17, 2020, 1:50:12 AM6/17/20
to Django users
Hey amit, in your views you are getting id that you didn't pass in the url
in your url.py
 path('home/(?P<pk>\d+)/',views.EmployeeCBV.as_view(),name='home'),
Reply all
Reply to author
Forward
0 new messages