Я создал простую программу на Python, которая будет извлекать и добавлять данные в базу данных на основе пользовательского ввода. Для этого я использовал POST метод. Программа успешно работает в Postman, но когда я вызываю программу из приложения iOS, используя вызов API, программа показывает 500 error . Ошибки в exception.py и base.py . Моя программа приведена ниже
@api_view(["POST"])
def mg_grt(request):
if request.method == 'POST':
name = request.POST['name']
word = name.lower()
greet = Greet.objects.filter(grett=word)
if greet != 0:
d = Resp(rsp=word)
d.save()
r_val = Resp.objects.all()
rt = random.choice(r_val)
return HttpResponse(rt)
else:
return HttpResponse("Sorry...I didn't understand")
else:
return HttpResponse("Bad Request")
Ошибки:
File "/Library/Python/2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/rest_framework/views.py", line 483, in dispatch
response = self.handle_exception(exc)
File "/Library/Python/2.7/site-packages/rest_framework/views.py", line 443, in handle_exception
self.raise_uncaught_exception(exc)
File "/Library/Python/2.7/site-packages/rest_framework/views.py", line 480, in dispatch
response = handler(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/rest_framework/decorators.py", line 53, in handler
return func(*args, **kwargs)
File "/Users/abijith/Test5/tgpi/views.py", line 21, in mg_grt
name = request.POST['name']
File "/Library/Python/2.7/site-packages/django/utils/datastructures.py", line 85, in __getitem__
raise MultiValueDictKeyError(repr(key))
MultiValueDictKeyError: "u'name'"
[31/Aug/2018 10:20:45] "POST /grt/ HTTP/1.1" 500 14099