I have a website where I gave 2 different forms. Here is my HTML:
{% extends 'base.html' %}
{% block title %}
Home page
{% endblock %}
{% block content %}
<div class="pt-5">
<form action="data" method="POST" enctype="multipart/form-data">
<input type="file" name="file" accept=".csv, .xlsx, .xls" />
<input type="submit" name="form1" value="Submit"/>
</form>
</div>
<div class="pt-5">
<form action="data" method="POST" enctype="multipart/form-data">
<input type="file" name="file1" accept=".csv, .xlsx, .xls" />
<input type="file" name="file2" accept=".csv, .xlsx, .xls" />
<input type="submit" name="form2" value="Merge"/>
</form>
</div>
Both forms uploads files, the first form uploads just one file while the other form should Merge two files. Now both will actually to the same page. How can I differentiate between them? I searched and I have come across solutions like this:
if request.method == "POST":
if "form1" in request.form:
print("form1")
elif "form2" in request.form:
print("form2")
But this does not work for me, how can I know from which form my request is coming from? Thanks.
EDIT
The solution I provided above works now, I did not know why it did not work before...