Answer the question
In order to leave comments, you need to log in
Form with two submit | Django?
Hello! Please help me figure it out.
There is a form in which it is necessary to fasten two submit buttons. By pressing each of them, it is necessary to process the data of certain fields. An Internet search says that you need to specify an attribute with different names on these submits and name
check in the view whether this name is in request.POST
. I am using the following code and it does not work correctly. Request.POST does not have these names that I specified for the submit buttons. What am I doing wrong to solve this problem?
item_edit_form.html:
<form method="post" action="{% url 'адрес' %}" class='edit-form' enctype="multipart/form-data">
{% csrf_token %}
<!-- Здесь поля формы -->
<input type="submit" class="btn btn-success" value="Удалить" name='delete_submit'/>
<input type="submit" class="btn btn-success" value="Обновить данные" name='update_submit'/>
</form>
class ItemEditView(UpdateView):
def form_valid(self, form):
if 'update_submit' in self.request.POST:
# Использовать все поля формы
elif 'delete_submit' in self.request.POST:
# Использовать лишь одно поле формы
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question