首页 > 解决方案 > 当我以原始 json 格式从邮递员发送数据时......名称将不会接收数据......为什么

问题描述

这是我的代码....views.py 如果我使用来自邮递员的表单数据发送数据,它将接收数据。但是原始 json 数据不起作用为什么

from django.http import HttpResponse, JsonResponse
from django.shortcuts import render


# Create your views here.
from django.views.decorators.csrf import csrf_exempt


@csrf_exempt
def create_book(request):
    if request.method == "POST":
        name = request.POST.get('author_name')
        return JsonResponse({
            "name": name
        })

    else:
        return JsonResponse({"name": "notfound"})

…………………………………………………………………………

标签: django-modelsdjango-viewspostman

解决方案


推荐阅读