我在 /app/index 'access_key'
MultiValueDictKeyError
收到错误。我在 views.py 写道
from django.shortcuts import render
from .forms import UserIDForm
from .models import User
import json
from django.http.response import JsonResponse
from django.http import HttpResponseNotFound
def index(request):
inp_id = request.POST['access_key']
find = False
if inp_id == 100:
find = True
if find:
id_json = {"id": 100}
else:
return HttpResponseNotFound()
return JsonResponse(id_json, safe=False)
现在我使用POSTMAN
,我理想的系统是当我在POSTMAN中发布密钥是access_key和值是100到http://localhost:8000/app/index
时,返回{"id":100}。我的代码中有什么问题?是统一码错误吗?我应该如何解决这个问题?
邮差
inp_id = request.POST.get('access_key', None)
并且您没有在与 POSTMAN 的 POST 请求中设置access_key
,这是正确的方法。