view.py:
@csrf_exempt
@permission_classes((AllowAny, ))
@api_view(['GET', 'POST'])
def testing(request):
if request.method == 'GET':
permission_classes = (permissions.IsAuthenticatedOrReadOnly,IsOwnerOrReadOnly)
snippets = Temperature.objects.all()
serializer = serializers.TemperatureSerializer(snippets, many=True)
return Response(serializer.data)
elif request.method == 'POST':
permission_classes = (permissions.IsAuthenticatedOrReadOnly,IsOwnerOrReadOnly)
serializer = serializers.TemperatureSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
url.py:
urlpatterns = [
url(r'^$', views.testing),
]
setting.py:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAdminUser',
'rest_framework.permissions.IsAuthenticated',
'rest_framework.permissions.AllowAny',
),
'PAGINATE_BY': 10,
}
please help,i have googled this,tryed to read up on Django REST framework permissions,and still i didn't find an answer.
I don't know what is wrong.
Please help me about this error
I get something like this:
"
HTTP 401 Unauthorized
WWW-Authenticate: Token
Allow: GET, POST, OPTIONS
Content-Type: application/json
Vary: Accept
{
"detail": "Authentication credentials were not provided."
}"