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
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/00451532-6e7f-433a-a21b-d8c5e2afecf6o%40googlegroups.com.