Django: DeleteView + HttpResponseNotAllowed









up vote
1
down vote

favorite












I found this DeleteView. Anyone can tell me what return HttpResponseNotAllowed(['POST'])is for? Should I add it to my own DeleteView as well?



class DiscountDelete(AdminPermissionRequiredMixin, DeleteView):
model = Discount

def get(self, *args, **kwargs):
return HttpResponseNotAllowed(['POST'])









share|improve this question

























    up vote
    1
    down vote

    favorite












    I found this DeleteView. Anyone can tell me what return HttpResponseNotAllowed(['POST'])is for? Should I add it to my own DeleteView as well?



    class DiscountDelete(AdminPermissionRequiredMixin, DeleteView):
    model = Discount

    def get(self, *args, **kwargs):
    return HttpResponseNotAllowed(['POST'])









    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I found this DeleteView. Anyone can tell me what return HttpResponseNotAllowed(['POST'])is for? Should I add it to my own DeleteView as well?



      class DiscountDelete(AdminPermissionRequiredMixin, DeleteView):
      model = Discount

      def get(self, *args, **kwargs):
      return HttpResponseNotAllowed(['POST'])









      share|improve this question













      I found this DeleteView. Anyone can tell me what return HttpResponseNotAllowed(['POST'])is for? Should I add it to my own DeleteView as well?



      class DiscountDelete(AdminPermissionRequiredMixin, DeleteView):
      model = Discount

      def get(self, *args, **kwargs):
      return HttpResponseNotAllowed(['POST'])






      python django






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 16:42









      Jon Programmer

      1808




      1808






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          With Django's class based views you can define a class variable for this;



          class DiscountDelete(AdminPermissionRequiredMixin, DeleteView):
          model = Discount
          http_method_names = ['post']


          Then if that view receives a get request it'll send back the 405 you're looking for.



          Docs on this are here; https://docs.djangoproject.com/en/2.1/ref/class-based-views/base/#django.views.generic.base.View.http_method_names






          share|improve this answer




















          • Ah perfect. I found on Classy CBV this way to write it: http_method_names = [u'get', u'post', u'put', u'patch', u'delete', u'head', u'options', u'trace'] Do you know what the u stands for?
            – Jon Programmer
            Nov 9 at 16:50







          • 1




            @JonProgrammer u'' is a unicode string. You might see this if you're using python 2 and have from __future__ import unicode_literals then print a string.
            – markwalker_
            Nov 9 at 16:52

















          up vote
          3
          down vote













          With the usual delete view, when you do a GET request you get a confirmation page. Then when you submit the form with a POST request, the object is deleted.



          The custom get() method is disabling GET requests. Perhaps it's not needed, because the delete requests are submitted from a different view (e.g. a list view).



          We can't tell whether or not you should add this functionality to your delete view. It's up to you.






          share|improve this answer




















          • And that's where ccbv.co.uk becomes a superb resource.
            – markwalker_
            Nov 9 at 16:56










          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',
          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%2f53229915%2fdjango-deleteview-httpresponsenotallowed%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          With Django's class based views you can define a class variable for this;



          class DiscountDelete(AdminPermissionRequiredMixin, DeleteView):
          model = Discount
          http_method_names = ['post']


          Then if that view receives a get request it'll send back the 405 you're looking for.



          Docs on this are here; https://docs.djangoproject.com/en/2.1/ref/class-based-views/base/#django.views.generic.base.View.http_method_names






          share|improve this answer




















          • Ah perfect. I found on Classy CBV this way to write it: http_method_names = [u'get', u'post', u'put', u'patch', u'delete', u'head', u'options', u'trace'] Do you know what the u stands for?
            – Jon Programmer
            Nov 9 at 16:50







          • 1




            @JonProgrammer u'' is a unicode string. You might see this if you're using python 2 and have from __future__ import unicode_literals then print a string.
            – markwalker_
            Nov 9 at 16:52














          up vote
          3
          down vote



          accepted










          With Django's class based views you can define a class variable for this;



          class DiscountDelete(AdminPermissionRequiredMixin, DeleteView):
          model = Discount
          http_method_names = ['post']


          Then if that view receives a get request it'll send back the 405 you're looking for.



          Docs on this are here; https://docs.djangoproject.com/en/2.1/ref/class-based-views/base/#django.views.generic.base.View.http_method_names






          share|improve this answer




















          • Ah perfect. I found on Classy CBV this way to write it: http_method_names = [u'get', u'post', u'put', u'patch', u'delete', u'head', u'options', u'trace'] Do you know what the u stands for?
            – Jon Programmer
            Nov 9 at 16:50







          • 1




            @JonProgrammer u'' is a unicode string. You might see this if you're using python 2 and have from __future__ import unicode_literals then print a string.
            – markwalker_
            Nov 9 at 16:52












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          With Django's class based views you can define a class variable for this;



          class DiscountDelete(AdminPermissionRequiredMixin, DeleteView):
          model = Discount
          http_method_names = ['post']


          Then if that view receives a get request it'll send back the 405 you're looking for.



          Docs on this are here; https://docs.djangoproject.com/en/2.1/ref/class-based-views/base/#django.views.generic.base.View.http_method_names






          share|improve this answer












          With Django's class based views you can define a class variable for this;



          class DiscountDelete(AdminPermissionRequiredMixin, DeleteView):
          model = Discount
          http_method_names = ['post']


          Then if that view receives a get request it'll send back the 405 you're looking for.



          Docs on this are here; https://docs.djangoproject.com/en/2.1/ref/class-based-views/base/#django.views.generic.base.View.http_method_names







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 16:47









          markwalker_

          4,27653572




          4,27653572











          • Ah perfect. I found on Classy CBV this way to write it: http_method_names = [u'get', u'post', u'put', u'patch', u'delete', u'head', u'options', u'trace'] Do you know what the u stands for?
            – Jon Programmer
            Nov 9 at 16:50







          • 1




            @JonProgrammer u'' is a unicode string. You might see this if you're using python 2 and have from __future__ import unicode_literals then print a string.
            – markwalker_
            Nov 9 at 16:52
















          • Ah perfect. I found on Classy CBV this way to write it: http_method_names = [u'get', u'post', u'put', u'patch', u'delete', u'head', u'options', u'trace'] Do you know what the u stands for?
            – Jon Programmer
            Nov 9 at 16:50







          • 1




            @JonProgrammer u'' is a unicode string. You might see this if you're using python 2 and have from __future__ import unicode_literals then print a string.
            – markwalker_
            Nov 9 at 16:52















          Ah perfect. I found on Classy CBV this way to write it: http_method_names = [u'get', u'post', u'put', u'patch', u'delete', u'head', u'options', u'trace'] Do you know what the u stands for?
          – Jon Programmer
          Nov 9 at 16:50





          Ah perfect. I found on Classy CBV this way to write it: http_method_names = [u'get', u'post', u'put', u'patch', u'delete', u'head', u'options', u'trace'] Do you know what the u stands for?
          – Jon Programmer
          Nov 9 at 16:50





          1




          1




          @JonProgrammer u'' is a unicode string. You might see this if you're using python 2 and have from __future__ import unicode_literals then print a string.
          – markwalker_
          Nov 9 at 16:52




          @JonProgrammer u'' is a unicode string. You might see this if you're using python 2 and have from __future__ import unicode_literals then print a string.
          – markwalker_
          Nov 9 at 16:52












          up vote
          3
          down vote













          With the usual delete view, when you do a GET request you get a confirmation page. Then when you submit the form with a POST request, the object is deleted.



          The custom get() method is disabling GET requests. Perhaps it's not needed, because the delete requests are submitted from a different view (e.g. a list view).



          We can't tell whether or not you should add this functionality to your delete view. It's up to you.






          share|improve this answer




















          • And that's where ccbv.co.uk becomes a superb resource.
            – markwalker_
            Nov 9 at 16:56














          up vote
          3
          down vote













          With the usual delete view, when you do a GET request you get a confirmation page. Then when you submit the form with a POST request, the object is deleted.



          The custom get() method is disabling GET requests. Perhaps it's not needed, because the delete requests are submitted from a different view (e.g. a list view).



          We can't tell whether or not you should add this functionality to your delete view. It's up to you.






          share|improve this answer




















          • And that's where ccbv.co.uk becomes a superb resource.
            – markwalker_
            Nov 9 at 16:56












          up vote
          3
          down vote










          up vote
          3
          down vote









          With the usual delete view, when you do a GET request you get a confirmation page. Then when you submit the form with a POST request, the object is deleted.



          The custom get() method is disabling GET requests. Perhaps it's not needed, because the delete requests are submitted from a different view (e.g. a list view).



          We can't tell whether or not you should add this functionality to your delete view. It's up to you.






          share|improve this answer












          With the usual delete view, when you do a GET request you get a confirmation page. Then when you submit the form with a POST request, the object is deleted.



          The custom get() method is disabling GET requests. Perhaps it's not needed, because the delete requests are submitted from a different view (e.g. a list view).



          We can't tell whether or not you should add this functionality to your delete view. It's up to you.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 16:53









          Alasdair

          174k25294303




          174k25294303











          • And that's where ccbv.co.uk becomes a superb resource.
            – markwalker_
            Nov 9 at 16:56
















          • And that's where ccbv.co.uk becomes a superb resource.
            – markwalker_
            Nov 9 at 16:56















          And that's where ccbv.co.uk becomes a superb resource.
          – markwalker_
          Nov 9 at 16:56




          And that's where ccbv.co.uk becomes a superb resource.
          – markwalker_
          Nov 9 at 16:56

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229915%2fdjango-deleteview-httpresponsenotallowed%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

          How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

          Syphilis

          Darth Vader #20