ListCreateAPIView Django rest framework Method \"POST\" not allowed

69 views
Skip to first unread message

Pradyum Gupta

unread,
Sep 25, 2020, 7:48:30 AM9/25/20
to django-res...@googlegroups.com

See I don't know this is actually a very weird error that am receiving.

 

Inside *Company App*

 

views.py

```python3

class CompanyView(generics.ListCreateAPIView):

    queryset = CompanyProfile.objects.all()

    serializer_class = RegisterationCompanySerializer

    permission_classes = (permissions.IsAuthenticated,)

 

    def post(self, request, *args, **kwargs):

        import pdb; pdb.set_trace() #check weather post request is getting called?

        return self.create(request, *args, **kwargs)

 

    def get_serializer(self, *args, **kwargs):

        import pdb; pdb.set_trace() #check weather post serializer is getting called?

        user_id = self.request.user.id

        serializer_class = self.get_serializer_class()

        .....

        kwargs['data'] = draft_request_data

        return serializer_class(*args, **kwargs)

 

```

 

urls.py inside the company app

```

urlpatterns = [

    path('', include(router.urls)),

 

    ## Register Company Process

    # path('List/', ListCompanyView.as_view()),

    path('Reg/', CompanyView.as_view()),

]

 

```

serializer.py

```python

class RegisterationCompanySerializer(serializers.ModelSerializer):

 

    class Meta:

        model = CompanyProfile

        fields = '__all__'

        extra_kwargs = {

                        'short_name': {'required': True},

                        ......

                        'user' : {'required': True},

                       }

 

```

 

models.py

```python

class CompanyProfile(models.Model):

    id                  = models.UUIDField(default=uuid.uuid4,

                                            editable=False,

                                            primary_key=True,

                                            verbose_name='ID',)

   ......

   verified             = models.BooleanField(default=False)

 

    def __str__(self):

        return str(self.id)

```

 

Also, note the ```company``` is present in ```INSTALLED_APPS```

 

But error am receiving this is on postman

```

{

    "detail": "Method \"POST\" not allowed."

}

```

 

on the terminal and tried PDB to check whether the function is getting called

```

Method Not Allowed: /company/Reg/

[Date and Time] "POST /company/Reg/ HTTP/1.1" 405 41

```

 

let me know if you are looking for more details.

 

Thanks in advance

 

Regards

Please also find the same question here https://stackoverflow.com/q/64063496/7999665

 

Linovia

unread,
Sep 25, 2020, 8:12:24 AM9/25/20
to django-res...@googlegroups.com
Hi,

What does your router look like ?

Regards,
Xavier O.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/PU1PR04MB23892F217077E14B042A0CB1A7360%40PU1PR04MB2389.apcprd04.prod.outlook.com.

Pradyum Gupta

unread,
Sep 26, 2020, 10:16:23 PM9/26/20
to Django REST framework
Yes, there was an issue with the router only 

I added this and now it's working

```path(''check/", include(router.urls)),```


Thanks & Regards

Reply all
Reply to author
Forward
0 new messages