Discussion:
method GET not allowed
Angel Omar Rojas Pacheco
2017-12-05 19:15:05 UTC
Permalink
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
http://127.0.0.1:8000/api/v1/dashboards/2

I try with

http://127.0.0.1:8000/api/v1/dashboards/2/

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.
--
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-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Xavier Ordoquy
2017-12-05 19:37:47 UTC
Permalink
Hi,
Post by Angel Omar Rojas Pacheco
url(r'^dashboards', views.DashboardViewCreate.as_view()),
catches all over the others because it doesn’t contains a termination clause.

Regards,
Xavier.
Post by Angel Omar Rojas Pacheco
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
dashboard_id = self.get_object(pk)
serializer = DashboardSerializer(dashboard_id, many=True)
return JsonResponse(serializer.data, safe=False)
user = User.objects.get(pk=pk)
return Dashboard.objects.filter(user_id=user.id)
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')
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
http://127.0.0.1:8000/api/v1/dashboards/2
I try with
http://127.0.0.1:8000/api/v1/dashboards/2/
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.
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
--
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-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Angel Omar Rojas Pacheco
2017-12-05 22:31:50 UTC
Permalink
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
Post by Angel Omar Rojas Pacheco
Hi,
url(r'^dashboards', views.DashboardViewCreate.as_view()),
catches all over the others because it doesn’t contains a termination clause.
Regards,
Xavier.
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
dashboard_id = self.get_object(pk)
serializer = DashboardSerializer(dashboard_id, many=True)
return JsonResponse(serializer.data, safe=False)
user = User.objects.get(pk=pk)
return Dashboard.objects.filter(user_id=user.id)
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')
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
http://127.0.0.1:8000/api/v1/dashboards/2
I try with
http://127.0.0.1:8000/api/v1/dashboards/2/
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.
--
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
For more options, visit https://groups.google.com/d/optout.
--
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-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...