Django REST Framework not generating form in Browsable API












1















Ok, I have a GenericAPIView that is supposed to generate a form in the Browsable API cause it declares a post method:



from rest_framework import status
from rest_framework.generics import GenericAPIView
from rest_framework.response import Response

from transacciones.serializers import BillSerializer


class ProcessBill(GenericAPIView):

serializer_class = BillSerializer

def post(self, request):

recieved_data = request.data

print(recieved_data)

return Response("Processed Bill", status=status.HTTP_200_OK)


But it doesn't generate a form. The view looks like this (it is in spanish, I translated the code to english so it is be more confortable to read):



enter image description here



I understand I get a 405 Method not Allowed cause I don't define a get method, only a post.



Im using Django 1.8, Django REST Framework 3.3.1 and python 3.4. I'm lost here. Any ideas?



EDIT



Also, if I use Postman (Chrome add on) the view responds correctly.










share|improve this question




















  • 1





    Possible duplicate of Django Rest Framework how to post data on the browsable API

    – Geotob
    Dec 17 '15 at 20:28











  • @Geotob This question uses a GenericAPIView, the old one uses a APIView. The difference is stated in the answer to this question by TomChristie : stackoverflow.com/questions/14616489/…

    – Alejandro Veintimilla
    Dec 17 '15 at 20:34











  • Anyway I thought It might be a good idea to create a new question, maybe it wasn't a good idea. I could delete one of them.

    – Alejandro Veintimilla
    Dec 17 '15 at 20:35











  • Sorry I didn't spot this! :( GenericAPIViews use a create(request, *args, **kwargs) method, not post

    – Geotob
    Dec 17 '15 at 20:38













  • @Geotob tried the create method, doesn't work. Anyway, GenericAPIView extends from the APIView, that what the docs say ... so it should have a post method.

    – Alejandro Veintimilla
    Dec 17 '15 at 20:47
















1















Ok, I have a GenericAPIView that is supposed to generate a form in the Browsable API cause it declares a post method:



from rest_framework import status
from rest_framework.generics import GenericAPIView
from rest_framework.response import Response

from transacciones.serializers import BillSerializer


class ProcessBill(GenericAPIView):

serializer_class = BillSerializer

def post(self, request):

recieved_data = request.data

print(recieved_data)

return Response("Processed Bill", status=status.HTTP_200_OK)


But it doesn't generate a form. The view looks like this (it is in spanish, I translated the code to english so it is be more confortable to read):



enter image description here



I understand I get a 405 Method not Allowed cause I don't define a get method, only a post.



Im using Django 1.8, Django REST Framework 3.3.1 and python 3.4. I'm lost here. Any ideas?



EDIT



Also, if I use Postman (Chrome add on) the view responds correctly.










share|improve this question




















  • 1





    Possible duplicate of Django Rest Framework how to post data on the browsable API

    – Geotob
    Dec 17 '15 at 20:28











  • @Geotob This question uses a GenericAPIView, the old one uses a APIView. The difference is stated in the answer to this question by TomChristie : stackoverflow.com/questions/14616489/…

    – Alejandro Veintimilla
    Dec 17 '15 at 20:34











  • Anyway I thought It might be a good idea to create a new question, maybe it wasn't a good idea. I could delete one of them.

    – Alejandro Veintimilla
    Dec 17 '15 at 20:35











  • Sorry I didn't spot this! :( GenericAPIViews use a create(request, *args, **kwargs) method, not post

    – Geotob
    Dec 17 '15 at 20:38













  • @Geotob tried the create method, doesn't work. Anyway, GenericAPIView extends from the APIView, that what the docs say ... so it should have a post method.

    – Alejandro Veintimilla
    Dec 17 '15 at 20:47














1












1








1








Ok, I have a GenericAPIView that is supposed to generate a form in the Browsable API cause it declares a post method:



from rest_framework import status
from rest_framework.generics import GenericAPIView
from rest_framework.response import Response

from transacciones.serializers import BillSerializer


class ProcessBill(GenericAPIView):

serializer_class = BillSerializer

def post(self, request):

recieved_data = request.data

print(recieved_data)

return Response("Processed Bill", status=status.HTTP_200_OK)


But it doesn't generate a form. The view looks like this (it is in spanish, I translated the code to english so it is be more confortable to read):



enter image description here



I understand I get a 405 Method not Allowed cause I don't define a get method, only a post.



Im using Django 1.8, Django REST Framework 3.3.1 and python 3.4. I'm lost here. Any ideas?



EDIT



Also, if I use Postman (Chrome add on) the view responds correctly.










share|improve this question
















Ok, I have a GenericAPIView that is supposed to generate a form in the Browsable API cause it declares a post method:



from rest_framework import status
from rest_framework.generics import GenericAPIView
from rest_framework.response import Response

from transacciones.serializers import BillSerializer


class ProcessBill(GenericAPIView):

serializer_class = BillSerializer

def post(self, request):

recieved_data = request.data

print(recieved_data)

return Response("Processed Bill", status=status.HTTP_200_OK)


But it doesn't generate a form. The view looks like this (it is in spanish, I translated the code to english so it is be more confortable to read):



enter image description here



I understand I get a 405 Method not Allowed cause I don't define a get method, only a post.



Im using Django 1.8, Django REST Framework 3.3.1 and python 3.4. I'm lost here. Any ideas?



EDIT



Also, if I use Postman (Chrome add on) the view responds correctly.







django django-rest-framework






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 17 '15 at 21:03







Alejandro Veintimilla

















asked Dec 17 '15 at 20:26









Alejandro VeintimillaAlejandro Veintimilla

2,442741102




2,442741102








  • 1





    Possible duplicate of Django Rest Framework how to post data on the browsable API

    – Geotob
    Dec 17 '15 at 20:28











  • @Geotob This question uses a GenericAPIView, the old one uses a APIView. The difference is stated in the answer to this question by TomChristie : stackoverflow.com/questions/14616489/…

    – Alejandro Veintimilla
    Dec 17 '15 at 20:34











  • Anyway I thought It might be a good idea to create a new question, maybe it wasn't a good idea. I could delete one of them.

    – Alejandro Veintimilla
    Dec 17 '15 at 20:35











  • Sorry I didn't spot this! :( GenericAPIViews use a create(request, *args, **kwargs) method, not post

    – Geotob
    Dec 17 '15 at 20:38













  • @Geotob tried the create method, doesn't work. Anyway, GenericAPIView extends from the APIView, that what the docs say ... so it should have a post method.

    – Alejandro Veintimilla
    Dec 17 '15 at 20:47














  • 1





    Possible duplicate of Django Rest Framework how to post data on the browsable API

    – Geotob
    Dec 17 '15 at 20:28











  • @Geotob This question uses a GenericAPIView, the old one uses a APIView. The difference is stated in the answer to this question by TomChristie : stackoverflow.com/questions/14616489/…

    – Alejandro Veintimilla
    Dec 17 '15 at 20:34











  • Anyway I thought It might be a good idea to create a new question, maybe it wasn't a good idea. I could delete one of them.

    – Alejandro Veintimilla
    Dec 17 '15 at 20:35











  • Sorry I didn't spot this! :( GenericAPIViews use a create(request, *args, **kwargs) method, not post

    – Geotob
    Dec 17 '15 at 20:38













  • @Geotob tried the create method, doesn't work. Anyway, GenericAPIView extends from the APIView, that what the docs say ... so it should have a post method.

    – Alejandro Veintimilla
    Dec 17 '15 at 20:47








1




1





Possible duplicate of Django Rest Framework how to post data on the browsable API

– Geotob
Dec 17 '15 at 20:28





Possible duplicate of Django Rest Framework how to post data on the browsable API

– Geotob
Dec 17 '15 at 20:28













@Geotob This question uses a GenericAPIView, the old one uses a APIView. The difference is stated in the answer to this question by TomChristie : stackoverflow.com/questions/14616489/…

– Alejandro Veintimilla
Dec 17 '15 at 20:34





@Geotob This question uses a GenericAPIView, the old one uses a APIView. The difference is stated in the answer to this question by TomChristie : stackoverflow.com/questions/14616489/…

– Alejandro Veintimilla
Dec 17 '15 at 20:34













Anyway I thought It might be a good idea to create a new question, maybe it wasn't a good idea. I could delete one of them.

– Alejandro Veintimilla
Dec 17 '15 at 20:35





Anyway I thought It might be a good idea to create a new question, maybe it wasn't a good idea. I could delete one of them.

– Alejandro Veintimilla
Dec 17 '15 at 20:35













Sorry I didn't spot this! :( GenericAPIViews use a create(request, *args, **kwargs) method, not post

– Geotob
Dec 17 '15 at 20:38







Sorry I didn't spot this! :( GenericAPIViews use a create(request, *args, **kwargs) method, not post

– Geotob
Dec 17 '15 at 20:38















@Geotob tried the create method, doesn't work. Anyway, GenericAPIView extends from the APIView, that what the docs say ... so it should have a post method.

– Alejandro Veintimilla
Dec 17 '15 at 20:47





@Geotob tried the create method, doesn't work. Anyway, GenericAPIView extends from the APIView, that what the docs say ... so it should have a post method.

– Alejandro Veintimilla
Dec 17 '15 at 20:47












4 Answers
4






active

oldest

votes


















1














You can use this



from rest_framework.generics import CreateAPIView
from rest_framework.mixins import CreateModelMixin
from rest_framework.response import Response

from transacciones.serializers import BillSerializer


class ProcessBill(CreateModelMixin, GenericAPIView):
serializer_class = BillSerializer

def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)

def create(self, request, *args, **kwargs):
# Do whatever you want here

# Then invoke the create method and create your instance
return super().create(request, *args, **kwargs)


Or as an alternative, you just inherit from CreateAPIView which does essentially the same as the code above :)






share|improve this answer


























  • Thanks for the answer. It doesn't work. : /

    – Alejandro Veintimilla
    Dec 17 '15 at 20:49











  • hm yea @alejoss i didn't notice that generics need the post method.. too used to viewsets. learned something new:) see the edit above, works fine for me

    – Geotob
    Dec 17 '15 at 21:20





















1














If you are using generics.RetrieveUpdateDestroyAPIView then you will have to define permission_classes which can be custom.



class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
"""
Object RUD (Read Update Delete) API
"""
permission_classes = ( checkUserPermission, )
queryset = Object.objects.all()
serializer_class = ObjectSerializer


OR If you want to just test this, use permission_classes = ( AllowAny, )



class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
"""
Object RUD (Read Update Delete) API
"""
permission_classes = ( AllowAny, )
queryset = Object.objects.all()
serializer_class = ObjectSerializer





share|improve this answer































    0














    I had the same issue, with postman I saw it was a credential issue, so changing current user status to staff solved the problem.






    share|improve this answer































      0














      I ran into the same problem. In my case, the mistake was in the serializer, where I used django.db.models.CharField(...) instead of rest_framework.serializers.CharField(...).






      share|improve this answer























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34343638%2fdjango-rest-framework-not-generating-form-in-browsable-api%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1














        You can use this



        from rest_framework.generics import CreateAPIView
        from rest_framework.mixins import CreateModelMixin
        from rest_framework.response import Response

        from transacciones.serializers import BillSerializer


        class ProcessBill(CreateModelMixin, GenericAPIView):
        serializer_class = BillSerializer

        def post(self, request, *args, **kwargs):
        return self.create(request, *args, **kwargs)

        def create(self, request, *args, **kwargs):
        # Do whatever you want here

        # Then invoke the create method and create your instance
        return super().create(request, *args, **kwargs)


        Or as an alternative, you just inherit from CreateAPIView which does essentially the same as the code above :)






        share|improve this answer


























        • Thanks for the answer. It doesn't work. : /

          – Alejandro Veintimilla
          Dec 17 '15 at 20:49











        • hm yea @alejoss i didn't notice that generics need the post method.. too used to viewsets. learned something new:) see the edit above, works fine for me

          – Geotob
          Dec 17 '15 at 21:20


















        1














        You can use this



        from rest_framework.generics import CreateAPIView
        from rest_framework.mixins import CreateModelMixin
        from rest_framework.response import Response

        from transacciones.serializers import BillSerializer


        class ProcessBill(CreateModelMixin, GenericAPIView):
        serializer_class = BillSerializer

        def post(self, request, *args, **kwargs):
        return self.create(request, *args, **kwargs)

        def create(self, request, *args, **kwargs):
        # Do whatever you want here

        # Then invoke the create method and create your instance
        return super().create(request, *args, **kwargs)


        Or as an alternative, you just inherit from CreateAPIView which does essentially the same as the code above :)






        share|improve this answer


























        • Thanks for the answer. It doesn't work. : /

          – Alejandro Veintimilla
          Dec 17 '15 at 20:49











        • hm yea @alejoss i didn't notice that generics need the post method.. too used to viewsets. learned something new:) see the edit above, works fine for me

          – Geotob
          Dec 17 '15 at 21:20
















        1












        1








        1







        You can use this



        from rest_framework.generics import CreateAPIView
        from rest_framework.mixins import CreateModelMixin
        from rest_framework.response import Response

        from transacciones.serializers import BillSerializer


        class ProcessBill(CreateModelMixin, GenericAPIView):
        serializer_class = BillSerializer

        def post(self, request, *args, **kwargs):
        return self.create(request, *args, **kwargs)

        def create(self, request, *args, **kwargs):
        # Do whatever you want here

        # Then invoke the create method and create your instance
        return super().create(request, *args, **kwargs)


        Or as an alternative, you just inherit from CreateAPIView which does essentially the same as the code above :)






        share|improve this answer















        You can use this



        from rest_framework.generics import CreateAPIView
        from rest_framework.mixins import CreateModelMixin
        from rest_framework.response import Response

        from transacciones.serializers import BillSerializer


        class ProcessBill(CreateModelMixin, GenericAPIView):
        serializer_class = BillSerializer

        def post(self, request, *args, **kwargs):
        return self.create(request, *args, **kwargs)

        def create(self, request, *args, **kwargs):
        # Do whatever you want here

        # Then invoke the create method and create your instance
        return super().create(request, *args, **kwargs)


        Or as an alternative, you just inherit from CreateAPIView which does essentially the same as the code above :)







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 17 '15 at 21:19

























        answered Dec 17 '15 at 20:42









        GeotobGeotob

        1,670714




        1,670714













        • Thanks for the answer. It doesn't work. : /

          – Alejandro Veintimilla
          Dec 17 '15 at 20:49











        • hm yea @alejoss i didn't notice that generics need the post method.. too used to viewsets. learned something new:) see the edit above, works fine for me

          – Geotob
          Dec 17 '15 at 21:20





















        • Thanks for the answer. It doesn't work. : /

          – Alejandro Veintimilla
          Dec 17 '15 at 20:49











        • hm yea @alejoss i didn't notice that generics need the post method.. too used to viewsets. learned something new:) see the edit above, works fine for me

          – Geotob
          Dec 17 '15 at 21:20



















        Thanks for the answer. It doesn't work. : /

        – Alejandro Veintimilla
        Dec 17 '15 at 20:49





        Thanks for the answer. It doesn't work. : /

        – Alejandro Veintimilla
        Dec 17 '15 at 20:49













        hm yea @alejoss i didn't notice that generics need the post method.. too used to viewsets. learned something new:) see the edit above, works fine for me

        – Geotob
        Dec 17 '15 at 21:20







        hm yea @alejoss i didn't notice that generics need the post method.. too used to viewsets. learned something new:) see the edit above, works fine for me

        – Geotob
        Dec 17 '15 at 21:20















        1














        If you are using generics.RetrieveUpdateDestroyAPIView then you will have to define permission_classes which can be custom.



        class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
        """
        Object RUD (Read Update Delete) API
        """
        permission_classes = ( checkUserPermission, )
        queryset = Object.objects.all()
        serializer_class = ObjectSerializer


        OR If you want to just test this, use permission_classes = ( AllowAny, )



        class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
        """
        Object RUD (Read Update Delete) API
        """
        permission_classes = ( AllowAny, )
        queryset = Object.objects.all()
        serializer_class = ObjectSerializer





        share|improve this answer




























          1














          If you are using generics.RetrieveUpdateDestroyAPIView then you will have to define permission_classes which can be custom.



          class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
          """
          Object RUD (Read Update Delete) API
          """
          permission_classes = ( checkUserPermission, )
          queryset = Object.objects.all()
          serializer_class = ObjectSerializer


          OR If you want to just test this, use permission_classes = ( AllowAny, )



          class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
          """
          Object RUD (Read Update Delete) API
          """
          permission_classes = ( AllowAny, )
          queryset = Object.objects.all()
          serializer_class = ObjectSerializer





          share|improve this answer


























            1












            1








            1







            If you are using generics.RetrieveUpdateDestroyAPIView then you will have to define permission_classes which can be custom.



            class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
            """
            Object RUD (Read Update Delete) API
            """
            permission_classes = ( checkUserPermission, )
            queryset = Object.objects.all()
            serializer_class = ObjectSerializer


            OR If you want to just test this, use permission_classes = ( AllowAny, )



            class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
            """
            Object RUD (Read Update Delete) API
            """
            permission_classes = ( AllowAny, )
            queryset = Object.objects.all()
            serializer_class = ObjectSerializer





            share|improve this answer













            If you are using generics.RetrieveUpdateDestroyAPIView then you will have to define permission_classes which can be custom.



            class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
            """
            Object RUD (Read Update Delete) API
            """
            permission_classes = ( checkUserPermission, )
            queryset = Object.objects.all()
            serializer_class = ObjectSerializer


            OR If you want to just test this, use permission_classes = ( AllowAny, )



            class ObjectDetail(generics.RetrieveUpdateDestroyAPIView):
            """
            Object RUD (Read Update Delete) API
            """
            permission_classes = ( AllowAny, )
            queryset = Object.objects.all()
            serializer_class = ObjectSerializer






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 10 '17 at 8:37









            SuperNovaSuperNova

            6,19523323




            6,19523323























                0














                I had the same issue, with postman I saw it was a credential issue, so changing current user status to staff solved the problem.






                share|improve this answer




























                  0














                  I had the same issue, with postman I saw it was a credential issue, so changing current user status to staff solved the problem.






                  share|improve this answer


























                    0












                    0








                    0







                    I had the same issue, with postman I saw it was a credential issue, so changing current user status to staff solved the problem.






                    share|improve this answer













                    I had the same issue, with postman I saw it was a credential issue, so changing current user status to staff solved the problem.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 11 '17 at 5:58









                    Natiq VahabovNatiq Vahabov

                    412410




                    412410























                        0














                        I ran into the same problem. In my case, the mistake was in the serializer, where I used django.db.models.CharField(...) instead of rest_framework.serializers.CharField(...).






                        share|improve this answer




























                          0














                          I ran into the same problem. In my case, the mistake was in the serializer, where I used django.db.models.CharField(...) instead of rest_framework.serializers.CharField(...).






                          share|improve this answer


























                            0












                            0








                            0







                            I ran into the same problem. In my case, the mistake was in the serializer, where I used django.db.models.CharField(...) instead of rest_framework.serializers.CharField(...).






                            share|improve this answer













                            I ran into the same problem. In my case, the mistake was in the serializer, where I used django.db.models.CharField(...) instead of rest_framework.serializers.CharField(...).







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 28 '18 at 16:22









                            ArjenArjen

                            5491512




                            5491512






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34343638%2fdjango-rest-framework-not-generating-form-in-browsable-api%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                                Calculate evaluation metrics using cross_val_predict sklearn

                                Insert data from modal to MySQL (multiple modal on website)