Meine API:Warum funktioniert die rest_framework.authentication.BasicAuthentication nicht in meinen Codes?
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
Die oben ist mein API views.py. Ich benutzte den Postboten, um PUT zu machen. Ich habe nichts in der Header-Autorisierung hinzugefügt (keine HTTP_AUTHORIZATION im Anforderungsheader), ich kann {'files': 'testing'} als meine Antwort bekommen.
Warum? Alles fehlt? Danke