- settings.py中将中间件csrf注释掉
‘django.middleware.csrf.CsrfViewMiddleware’, - index.html中新建URLSearchParams()对象传参
- views.py中用request.POST[’**’]取参数
def books(request):
books = [
{'id': 1, "title": "Python", "price": 89.6},
{'id': 2, "title": "Flask", "price": 90.6},
{'id': 3, "title": "Django", "price": 85.6},
]
if request.method=='GET':
id=request.GET.get('id')
idd=request.GET.get('idd')
print(id)
print(idd)
if request.method=='POST':
id1=request.POST['id']
print(id1)
return JsonResponse(books,safe=False)



