I am wondering if it was okay for him (especially in Django) to have a URL intended only for actions with side effects that are intended only for POST access, and this is mostly invisible to the user. Say, in order to make this specific, I have a small messaging system on my site and from their mailbox, the user should be able to do a bunch of things like:
- Delete message
- Mark message as read
- Report abuse as spam
With all of these things causing a page refresh but returning to the same page. I am wondering how to create my own urls and views about this. I see (at least) two options, and I have no idea which is more idiomatic.
Option 1)
You have a separate URL and view for each action. So / inbox / delete -message / maps to views.delete_message etc. At the end of each of these views, it redirects back to / inbox /.
I like the way things are clearly separated by this option. If the user somehow discovers that he is sending a GET request to / inbox / delete -message /, which is some kind of strange situation, though (am I throwing a page with an error? Do I redirect them silently?).
Option 2)
Use the same URL and view for each action and specify the POST parameter that identifies the action. That way, I will have one pretty long look in the Inbox, which will have a lot of if statements checking if request.POST ['action'] == 'delete' or request.POST ['delete'] = is being requested = 'true' or something else.
This option seems less clean to me, but I also feel that it is more common.
What would be preferable to Djangonauts? Or is there another option that is better than any of the above?
source share