перенаправление request.post для входа на сервер разработки django - PullRequest
0 голосов
/ 28 апреля 2020
from rest_framework.authentication import BasicAuthentication
from rest_framework.permissions import IsAuthenticated

class TestApiView(APIView):
    authentication_classes = [BasicAuthentication]
    permission_classes = [IsAuthenticated]

    def post(self, *args, **kwargs):
        return Response({'method': 'post'})

    def get(self, *args, **kwargs):
        return Response({'method': 'get'})

Представление доступно по URL-адресу http://127.0.0.1: 8000 / test / и работает, как и ожидалось, в браузере

Я вызываю API из python shell

import requests
from requests.auth import HTTPBasicAuth
url = 'http://127.0.0.1:8000/test/'
my_auth = HTTPBasicAuth('<my-user-name>', '<password>')
r=requests.post(url, auth=my_auth)
print(r.json())

{'method': 'get'}

Метод get вызывается вместо post в django сервер разработки . Я хочу, чтобы он работал на django сервере разработки. Он отлично работает на моем nginx -gunicorn- django сервере. Любая помощь приветствуется.

...