title: Delete Row from html table on icon click using flask, python, and sqlite
body: <p>I'm at a total loss on how to do this. I'm building a webpage and I need to be able to delete a record from my SQLite database once the user clicks the delete icon on the front end. Can someone please help me figure out how to do this? I have no experience using PHP so any reference to that just won't be helpful. As you can see from the entries page a user will be able to see all entries entered already; each entry_id is unique. If a user clicks delete, then I want the row deleted from the entries page, and also deleted from the DB. If a user clicks the edit button that's another beast, and I'd like to be able to show on click, the populated form in edit mode, and once a user makes changes and click save, then have those changes updated in the DB as well.</p>
  <p>Here's my html code:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>{% extends "layout.html" %}
  
  {% block title %}
      index
  {% endblock %}
  
  {% block main %}
  
  {% if msg %}
  &lt;div class="alert alert-danger" role="alert"&gt; {{ msg }}
  &lt;/div&gt;
  {% endif %}
  &lt;div&gt;
  &lt;form method="POST" action="/entries"&gt;
      &lt;table class="table table-hover table-sm table-bordered"&gt;
          &lt;thead class="thead-light"&gt;
              &lt;tr&gt;
                  &lt;th class="col-auto"&gt; ID &lt;/th&gt;
                  &lt;!--&lt;th class="col-auto" style="display:none;"&gt; entryid&lt;/th&gt;--&gt;
                  &lt;th class="col-auto"&gt; Edit &lt;/th&gt;
                  &lt;th class="col-auto"&gt; Delete &lt;/th&gt;
                  &lt;th class="col-auto"&gt;View&lt;/th&gt;
                  &lt;th class="col-auto"&gt;Date&lt;/th&gt;
                  &lt;th class="left"&gt;Title&lt;/th&gt;
                  &lt;th class="left"&gt;Notes&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
  
          &lt;tbody &gt;
  
              {% for row in entrylist %}
                  &lt;tr&gt;
                      &lt;td id="{{row.entry_id}}"&gt;&lt;/td&gt;
                      &lt;!--&lt;td style="display:none;" id="{{row.entry_id}}"&gt; {{row.entry_id}}--&gt;
                      &lt;td&gt; &lt;a title="Add" data-toggle="tooltip" class="btn" id="{{row.entry_id}}"&gt;&lt;i class="bi bi-pencil-fill"&gt; &lt;/i&gt;&lt;/a&gt;&lt;/td&gt;
                      &lt;td&gt; &lt;a class="btn" data-toggle="tooltip" title="delete" id="{{row.entry_id}}"&gt;&lt;i class="bi bi-trash" style="color:red;"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/td&gt;
                      &lt;td&gt; &lt;a class="btn" data-toggle="tooltip" title = "view" id="{{row.entry_id}}"&gt;&lt;i class="bi bi-journals"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/td&gt;
                      &lt;td id="{{row.entry_id}}"&gt; {{row.entry_dt}}&lt;/td&gt;
                      &lt;td class="ellipsistd" id="{{row.entry_id}}"&gt; {{row.title }} &lt;/td&gt;
                      &lt;td class="ellipsis" id ="{{row.entry_id}}"&gt;{{row.notes }}&lt;/td&gt;
                  &lt;/tr&gt;
              {% endfor %}
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  {% endblock %}</code></pre>
  </div>
  </div>
  </p>
  <p>Here's my flask code:</p>
  <pre><code>@app.route(&quot;/entries&quot;, methods=['GET'])
  @login_required
  def entries():
  if request.method == &quot;GET&quot;:
      entrylist = db.execute (&quot;SELECT * FROM entries WHERE id = ? AND entry_dt &lt;&gt; '' ORDER BY entry_id&quot;, session[&quot;user_id&quot;])
      # print(entrylist)
      return render_template (&quot;entries.html&quot;, entrylist = entrylist)
  </code></pre>