我有以下代码片段:
from django.shortcuts import render
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
# Create your views here.
@csrf_exempt
def ajax_post_view(request):
if request.method == "POST":
foo = request.POST.get('Foo')
print(foo)
return JsonResponse(foo, safe=False)
else:
return JsonResponse("Not a POST method", safe=False)
我正在从POSTMAN发出POST请求,该请求在响应中显示空值:-
我想念什么?
它不是适当的端点。您需要使用类似Django rest框架的工具
这将是最简单的方法https://www.django-rest-framework.org/api-guide/views/#function-based-views
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句