tags:

views:

95

answers:

1

Can I simulate form like behaviour when a user clicks on a simple link?

For example, can I have in views.py

def remove(request, entity_id):
   #remove the object with entity_id here

And in the HTML

<a href="profile/remove/{{ obj.entity_id }}">

And in the urls.py

(r'^app/profile/remove/(?P<entity_id>\d+)', 'app.views.remove')

Or do I have to use a proper HTML form like in the tutorial?

+4  A: 

GET/HEAD requests should not have any harmful side-effects (from HTTP 1.1 spec, 9.1: "In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval."), that's what POST/PUT/DELETE methods are for.

Other than that - Django won't forbid deleting a row from DB on GET request, if that's what you ask.

PiotrLegnica
Seconded, **always** use `post` for deletion.
voyager
you could also use delete for delete. http has several methods! of course you cannot use a form to generate a delete request (That i know of)
TokenMacGuy
There are other methods, but adoptance across browsers are few, far between and different. If you don't want headaches, I'd recommend using `post` and `get` exclusively for web pages.
voyager