/ app / index"' access_key'"的MultiValueDictKeyError

时间:2017-11-01 08:11:28

标签: python django

我在 / app / index MultiValueDictKeyError收到错误'access_key'。我在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,我理想的系统就是当我发布Key时,access_key&在POSTMAN中,值为http://localhost:8000/app/index,返回{" id":100}。我的代码中有什么问题?它是unicode错误吗?我该如何解决这个问题?

POSTMAN

1 个答案:

答案 0 :(得分:0)

inp_id = request.POST.get('access_key', None)

并且您没有使用POSTMAN在帖子请求中设置access_keythis是正确的方式。