我在頁面上有兩個按鈕:關注並取消關注,如果用戶沒有關注某人,則會顯示關注按鈕,反之亦然。我有以下代碼,但出於某種原因,只有取消關注按鈕的作品。按鈕不起作用 - 我點擊它並沒有任何反應。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%}
這是如此明顯,但我甚至沒有想到這一點。謝謝 :) –