To my knowledge, if you have several buttons in the same form you can not submit this form to different pages unless you use Javascript to change the action
of form
. What you can do is have a generic view that "routes" the call to a different view depending on which button was clicked.
def view_generica(request, *args, **kwargs):
view_certa = None
if request.GET['buscar']:
view_certa = uma_view
elif request.GET['editar']:
view_certa = outra_view
elif request.GET['apagar']:
view_certa = terceira_view
else
return HttpResponse("Erro")
return view_certa(request, *args, **kwargs)
Note: the code to deal with the specific button that was clicked came of that reply in Soen. I haven’t tested it, so I can’t say for sure if it works in practice.
Another alternative is to use common links (a
) instead of buttons, and style them to look like buttons. In that case, you must correctly assign the href
in your template to load the view with the right parameters (i.e. identifying the item located in your search).
Finally, you can create a form
different for each button, assigning the action
according. If the data returned by your template is immutable, it may be a good option. Each form
then repeat the data (identification) of the returned item, in a Hidden input for example (to be sent to the view next to the form submission).