【发布时间】:2020-12-20 17:25:37
【问题描述】:
我有以下代码sn-p:-
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 请求,该请求显示空值作为响应:-
我错过了什么?
【问题讨论】:
-
您是否尝试过 curl 命令只是为了确保它不是邮递员
-
curl -X POST -H "Content-Type: application/json" \ -d '{"Foo": "Bar", "email": "linuxize@example.com"}' \ localhost:8080/ajax_post_view
-
上面的 curl 命令给了我 None
-
你能分享你的
urls.py吗? -
路径('ajax_post_view', core_views.ajax_post_view, name="ajax_post_view"),