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'])
python django
add a comment |
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'])
python django
add a comment |
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'])
python django
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
python django
asked Nov 9 at 16:42
Jon Programmer
1808
1808
add a comment |
add a comment |
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
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
@JonProgrammeru''
is a unicode string. You might see this if you're using python 2 and havefrom __future__ import unicode_literals
then print a string.
– markwalker_
Nov 9 at 16:52
add a comment |
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.
And that's where ccbv.co.uk becomes a superb resource.
– markwalker_
Nov 9 at 16:56
add a comment |
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
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
@JonProgrammeru''
is a unicode string. You might see this if you're using python 2 and havefrom __future__ import unicode_literals
then print a string.
– markwalker_
Nov 9 at 16:52
add a comment |
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
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
@JonProgrammeru''
is a unicode string. You might see this if you're using python 2 and havefrom __future__ import unicode_literals
then print a string.
– markwalker_
Nov 9 at 16:52
add a comment |
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
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
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
@JonProgrammeru''
is a unicode string. You might see this if you're using python 2 and havefrom __future__ import unicode_literals
then print a string.
– markwalker_
Nov 9 at 16:52
add a comment |
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
@JonProgrammeru''
is a unicode string. You might see this if you're using python 2 and havefrom __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
add a comment |
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.
And that's where ccbv.co.uk becomes a superb resource.
– markwalker_
Nov 9 at 16:56
add a comment |
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.
And that's where ccbv.co.uk becomes a superb resource.
– markwalker_
Nov 9 at 16:56
add a comment |
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.
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.
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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