I'm creating this online simple webbapp, into i need to know what user voted. In the home page, I can see the list of "surveys", with two options in a radiobutton, and a submit button, as you can see in the following code
{% for element in range(1,datas.count()+1) %}
{% if datas.filter_by(id=element).first().user_name != user.name %}
<form action="post">
<fieldset style="border:{% if user.name in datas.filter_by(id=element).first().voters %}#f00 solid 2px {% else %}#00f solid 2px{% endif %};" class="fild">
<legend>{{ datas.filter_by(id=element).first().question }}</legend>
<br><br>
{{ datas.filter_by(id=element).first().fAnsw }} <input type="radio" name="opt" value="fa"/>
{% if user.name in datas.filter_by(id=element).first().voters %}
<progress value="0" max="100"></progress>
{% endif %}
{{ datas.filter_by(id=element).first().sAnsw }}<input type="radio" name="opt" value="sa"/>
{% if user.name in datas.filter_by(id=element).first().voters %}
<progress value="0" max="100"></progress>
{% endif %}
<br><br>
{% if user.name not in datas.filter_by(id=element).first().voters %}
<button type="submit" id="ans">Conferma</button>
{% endif %}
</fieldset>
</form>
{% endif %}
{% endfor %}
Now, I want to put on the vote on the database, based on what the users chose. So, I wrote the following code in Flask
@views.route("/", methods=["GET", "POST"])
@views.route("/home", methods=["GET", "POST"])
@login_required
def home():
if request.method =="POST":
selected = request.form.getlist('opt')
print(selected)
return render_template("home.html", user=current_user, datas=Refs.query)
Then, after a lot of resarch, I haven't found out why, when I press a submit button it redirect me to a page with the following link:
http://127.0.0.1:5000/post?opt=fa
and so it gaves me a 404. I would like to know why it doesn't redirect me to the same page, so I can handle it via the Flask code. And after that, how can I pass the survey that user touched? I have some issues. Please help