title: HTML form button not deleting rows from sqlite database
body: <p>I have built a forum in pythonanywhere using python and html, in which users can post information that gets inserted into a sqlite database. At the bottom of each post is a delete button that will delete the post that it's under from the database and refresh the page. Right now the delete button only refreshes the page while the post remains. I am wondering how to edit the code so that the post which the form button is attached to is deleted and the page is refreshed.</p>
  
  <p>HTML Code snippet</p>
  
  <pre><code>{% for post in forumposts %}
  &lt;tr&gt;
      &lt;td&gt;
      &lt;h1&gt;{{post[1]}}&lt;/h1&gt;
      &lt;h3&gt;{{post[3]}}&lt;/h3&gt;
      &lt;p&gt;{{post[2]}}&lt;/p&gt;
      &lt;p&gt;{{post[6]}}&lt;/p&gt;
      &lt;img src="{{post[7]}}" alt="Wrong image link."&gt;
      &lt;p&gt;&lt;/p&gt;
      &lt;form action="{{ url_for('delete_post') }}" method=POST class=delete-post&gt;
      &lt;input type=hidden value="{{ postid }}"name=post_to_delete&gt;&lt;/input&gt;
      &lt;input type=submit&gt;&lt;/input&gt;
      &lt;/form&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
      {%endfor%}
  &lt;/table&gt;
  </code></pre>
  
  <p>Python Code snippet</p>
  
  <pre><code>@app.route('/delete', methods=['POST'])
  def delete_post():
      db = connect_db()
      db.execute('DELETE FROM posts WHERE postid = ?', [request.form['post_to_delete']])
      db.commit()
      db.close()
      return redirect(url_for('forum'))
  </code></pre>