Ash Pereira Ash Pereira - 11 months ago 83
CSS Question

Python Flask Submit Button Not Working

I have two buttons on a page: follow and unfollow, the follow button is displayed if the user is not following a person and vice versa. I have the following code but for some reason only the unfollow button works. The follow button doesn't do anything - I click on it and nothing happens.

if request.method == 'POST':
if request.form['submit'] == 'Follow':
c.execute("INSERT INTO users_followers(username,following) VALUES(?,?)",(session['username'],username,))
elif request.form['submit'] == 'Unfollow':
c.execute("DELETE FROM users_followers WHERE username = ? AND following = ?",(session['username'],username,))
return redirect(url_for("profilepage",username=username))

HTML Code:

{%if profile[0][1] == current%}
{% if following == True %}
<form action="/profile/{{username}}" class="form" method="post">
<input class="btn btn--sm type--uppercase" name="submit" style="background: #e74c3c;border-color: #c0392b;color:white;width:100px;" type="submit" value="Unfollow">
<input class="btn btn--sm type--uppercase" name="submit" style="background: #4a90e2;border-color: #4a90e2;color:white;width:100px;" type="submit" value="Follow">
<a class="btn btn--sm btn--primary-2 type--uppercase" href="#"><span class="btn__text">Send Message</span></a>

Answer Source

You are not printing the form tag if following is not true. Move the following code out of the If statement.

<form action="/profile/{{username}}" class="form" method="post">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download