#14558 closed (fixed)
Generic View http_method bug
| Reported by: | pyrou | Owned by: | nobody |
|---|---|---|---|
| Component: | Generic views | Version: | dev |
| Severity: | Keywords: | ||
| Cc: | michael.hurni@… | Triage Stage: | Accepted |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
In generic views, you can find some http_method alias, just like in DeleteView (inherited from DeletionMixin)
post = delete
but if you override the orginal "delete" method in your own view :
class myDeleteView(DeleteView):
def delete(self, request, *args, **kwargs):
print "some console log"
return super(DeleteView, self).delete(self, request, *args, **kwargs)
your log is never printed, because your browser will use POST method, and so the original delete method is called instead of the overriden one.
Adding everytime the alias post = delete is not "DRY-ful"..
This way seems to be more "correct" for every alias:
def post(self, *args, **kwargs):
return self.delete(*args, **kwargs)
Attachments (1)
Change History (5)
follow-up: 2 comment:1 by , 15 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 15 years ago
| Cc: | added |
|---|
Replying to lrekucki:
This is a problem. Personally, I'm not very happy with either way of aliasing, because there is no way to get rid of the alias. With the alias always there, you can't create a view that deletes on DELETE and creates a child resource on POST (which is the original meaning of that HTTP verb).
There is also an slight inconsistency in UpdateView, which aliases POST to PUT, but IMHO this is a part of a larger issue.
You just have to create two methods, that will rid the "View" of its alias, it's not a problem in either way of aliasing.
class myRestUpdateView(UpdateView):
def delete(self, request, *args, **kwargs):
# delete
def post(self, request, *args, **kwargs):
# create a child ressource
The only point I want to fix is "keeping" the link between two methods when you override the original method (in my first example, the delete method)
by , 15 years ago
| Attachment: | edit.py.diff added |
|---|
comment:3 by , 15 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
This is a problem. Personally, I'm not very happy with either way of aliasing, because there is no way to get rid of the alias. With the alias always there, you can't create a view that deletes on DELETE and creates a child resource on POST (which is the original meaning of that HTTP verb).
There is also an slight inconsistency in UpdateView, which aliases POST to PUT, but IMHO this is a part of a larger issue.