Method Not Allowed: /schedule/3/
Remove Isauthenticated from rest_framework in settings.pyOn Mon, Oct 22, 2018, 11:22 AM Phako Perez <13.phakman@gmail.com> wrote:Hi all,--i'm really new on Django, trying to create an RESTful API, and getting this error:curl -i -U Elly:Elly -H "Content-Type: application/json" -X GET http://192.168.100.22:8000/schedule/3/
HTTP/1.1 403 Forbidden
Date: Mon, 22 Oct 2018 05:44:40 GMT
Server: WSGIServer/0.2 CPython/3.6.3
Content-Type: application/json
Vary: Accept, Cookie
Allow: OPTIONS
X-Frame-Options: SAMEORIGIN
Content-Length: 58
{"detail":"Authentication credentials were not provided."}
on my settings.py added belowREST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.permissions.IsAuthenticated'
),
}views.pyfrom schedule.models import Schedule
from users.models import User
from rest_framework import exceptions
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from rest_framework.permissions import IsAuthenticated
from schedule.serializers import ScheduleSerializer
class ScheduleList(APIView):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def authenticate(self, request):
username = request.META.get('X_USERNAME')
if not username:
return None
try:
user = User.objects.get(username=username)
except:
raise exceptions.AuthenticationFailed('No such user')
return Response(user, None)
queryset = Schedule.objects.all().filter(user=User.objects.all().filter(id=5)[0])
serializer_class = ScheduleSerializer
def perform_create(self, serializer):
serializer.save(user=self.request.user)
class ScheduleDetail(APIView):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def authenticate(self, request):
username = request.META.get('X_USERNAME')
if not username:
return None
try:
user = User.objects.get(username=username)
except:
raise exceptions.AuthenticationFailed('No such user')
return Response(user, None)
serializer_class = ScheduleSerializer
def get_queryset(self):
return Schedule.objects.all().filter(user=User.objects.all().filter(id=5)[0])thanks in advance
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAF%3Duzp30Enf%2BE7mWHXG6t2ZAj5YKc11oQkg4HSQOPaHTOO0QsA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
************************************************************************
This e-mail and all attachments are intended solely for use by the intended recipient and may contain confidential / proprietary information of KiwiTech, LLC, subject to important disclaimers and conditions including restrictions on the use, disclosure, transfer or export of such information. If you have received this message in error or are not the named recipient(s), please immediately notify the sender at the telephone number stated above or by reply e-mail and delete this e-mail from your computer
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJOHC1wHOa0-2G%2B8RHrvWi4JzX0-UeX7w%3DAVJ%3DEb_4PHT4OiZw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAF%3Duzp3WH3SYKNg979U5H%2B2F_ao4bk1BAb11T7dSy3K0ZD4Ckg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment