0
マイAPI:rest_framework.authentication.BasicAuthenticationが自分のコードで動作しないのはなぜですか?
from rest_framework.authentication import BasicAuthentication
"""A simple API for file upload."""
class FileUploadView(APIView):
parser_classes = (MultiPartParser,)
authentication_classes = (BasicAuthentication,)
@method_decorator(csrf_exempt)
def dispatch(self, request, *args, **kwargs):
return super(FileUploadView, self).dispatch(request, *args, **kwargs)
def put(self, request):
print "request:", str(request.META)
print "request:", str(request.user.username)
try:
data = {'files': 'testing'}
response = Response(data)
except Exception as e:
print "Exception when put file:", e
data = { 'error' : str(e) }
response = Response(data)
return response
は、上記の私のAPI views.pyです。私はPUTをするために郵便配達員を使いました。私はヘッダーの承認(要求ヘッダーにHTTP_AUTHORIZATIONがありません)に何も追加しませんでした。{'files': 'testing'}を私の回答として得ることができます。
なぜですか?何かが足りない?ありがとう