运行服务器后,由于as_view()接受1个位置参数,但给出了2个位置参数,我得到了错误,请看下面的代码并提出建议。
views.py
from django.views.generic import View
import json
class JsonCBV(View):
def get(self,request,*args, **kwargs):
emp_data=
{'eno':100,'ename':'pankhu','esal':300000,'eaddr':'pune'}
return JsonResponse(emp_data)
urls.py
from django.contrib import admin
from django.urls import path
from testapp import views
urlpatterns = [
path('admin/', admin.site.urls),
path('jsonapi3/', views.JsonCBV.as_view),
]
test.py
import requests
BASE_URL='http://127.0.0.1:8000/'
ENDPOINT='jsonapi3'
resp =requests.get(BASE_URL+ENDPOINT)
data=resp.json()
print('Data from django application')
print('#'*50)
print('Employee number:',data['eno'])
print('Employee name:',data['ename'])
print('Employee salary:',data['esal'])
print('Employee address:',data['eaddr'])
答案 0 :(得分:1)
在网址中,您必须在file1 = file1.drop(columns=0)
之后写括号
.as_view()