我在页面上有两个按钮:关注并取消关注,如果用户没有关注某人,则会显示关注按钮,反之亦然。我有以下代码,但出于某种原因,只有取消关注按钮的作品。按钮不起作用 - 我点击它并没有任何反应。Python Flask Submit Button Not Working
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,))
conn.commit()
return redirect(url_for("profilepage",username=username))
HTML代码:
{%if profile[0][1] == current%}
{%else%}
{% 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">
{%else%}
<input class="btn btn--sm type--uppercase" name="submit" style="background: #4a90e2;border-color: #4a90e2;color:white;width:100px;" type="submit" value="Follow">
{%endif%}
<a class="btn btn--sm btn--primary-2 type--uppercase" href="#"><span class="btn__text">Send Message</span></a>
</form>
{%endif%}
这是如此明显,但我甚至没有想到这一点。谢谢 :) –