method GET not allowed

3,049 views
Skip to first unread message

Angel Omar Rojas Pacheco

unread,
Dec 5, 2017, 2:15:05 PM12/5/17
to Django REST framework
hi everyone

I have a problem with allow method GET in my project, I find out problem but nothing working.

this is my urls.py file
from django.conf.urls import url
from apicolonybit.dashboard_clbt import views


urlpatterns = [
# dashboard
url(r'^dashboards/$', views.DashboardViewList.as_view()),
url(r'^dashboards', views.DashboardViewCreate.as_view()),
url(r'^dashboards/(?P<pk>[^/]+)', views.DashboardViewDetail.as_view(), name='dashboard-detail'),
url(r'^dashboards/(?P<pk>\d+)/update', views.DashboardViewUpdate.as_view()),

]

this is my views.py

class DashboardViewDetail(DetailView): # I try with APIView, and nothing working
queryset = Dashboard.objects.all()
serializer_class = DashboardSerializer
# permission_classes = (permissions.AllowAny,)
# model = Dashboard
# get_object and get recover detail from user
def get(self, request, pk, format=None):
dashboard_id = self.get_object(pk)
serializer = DashboardSerializer(dashboard_id, many=True)
return JsonResponse(serializer.data, safe=False)

def get_object(self, pk):
try:
user = User.objects.get(pk=pk)
return Dashboard.objects.filter(user_id=user.id)
except Dashboard.DoesNotExist:
raise Http404

my file serializers.py

from django.http import JsonResponse
from rest_framework import serializers
from apicolonybit.dashboard_clbt.models import Dashboard


dashboard_fields = ('id', 'component', 'column', 'position', 'user')


class DashboardSerializer(serializers.ModelSerializer):
class Meta:
model = Dashboard
fields = dashboard_fields


I try everything, but nothing working, the messages in my postman is 
{"detail":"Method \"GET\" not allowed."}


the url is

I try with


and not working too

and sametime not working method put and patch, just working method POST

in my postman headers sed
Allow POST, OPTIONS
Content-Length 40
Content-Type application/json
Date Tue, 05 Dec 2017 18:59:33 GMT
Server WSGIServer/0.2 CPython/3.5.3
Vary Accept
X-Frame-Options SAMEORIGIN

and don't know why not allow GET, PUT AND PATCH.

I see documentation, and I follow the instructions and not working

please help me.

































Xavier Ordoquy

unread,
Dec 5, 2017, 2:37:54 PM12/5/17
to django-res...@googlegroups.com
Hi,

This url:
    url(r'^dashboards', views.DashboardViewCreate.as_view()),
catches all over the others because it doesn’t contains a termination clause.

Regards,
Xavier.


--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

signature.asc

Angel Omar Rojas Pacheco

unread,
Dec 5, 2017, 5:31:50 PM12/5/17
to Django REST framework
Hi and thank for you reply,

I change the url

url(r'^dashboards/$', views.DashboardViewCreate.as_view()),

{

    "detail": "Method \"GET\" not allowed."
}

and still not working.

something idea more...

please

regards
Angel
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages