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 [email protected].
For more options, visit https://groups.google.com/d/optout.