title: python flask javascript DELETE 405 (METHOD NOT ALLOWED)
body: <p>I'm trying to add a button to delete a musical venue from my postgres database with flask-sqlalchemy on that venue's page and then redirect to the homepage but I'm getting the error</p>
  
  <pre><code>DELETE ip 405 (METHOD NOT ALLOWED)
  </code></pre>
  
  <p>in my console and </p>
  
  <pre><code>[28/May/2020
  14:12:49] "DELETE /deletevenue/1 HTTP/1.1" 302 -
  72.133.209.13 - - [28/May/2020
  14:12:50] "DELETE / HTTP/1.1" 405 -
  </code></pre>
  
  <p>in my terminal.  I don't know what is going wrong.  I can see that the correct venue_id is being sent to the route but I'm still getting this error.  I don't know what's wrong here.  This is the relevant code:</p>
  
  <p>app.py</p>
  
  <pre><code>@app.route('/deletevenue/&lt;venue_id&gt;', methods=['DELETE'])
  def delete_venue(venue_id):
    error = False
    venue = db.session.query(Venue).filter_by(id=venue_id).one()
    name = venue.name
    try:
      Venue.query.filter_by(id=venue_id).delete()
      db.session.commit()
    except:
      error = True
      db.session.rollback()
    finally:
      db.session.close()
    if error:
      flash('An Error occured.  The venue ' + name + ' could not be deleted.')
      return redirect(url_for('index'))
    else:
      flash('Success.  Venue ' + name + ' was deleted.')
      return redirect(url_for('index'))
  
  @app.route('/')
  def index():
    return render_template('pages/home.html')
  </code></pre>
  
  <p>show_venue.html</p>
  
  <pre><code>    &lt;div class="row"&gt;
          &lt;button class="btn btn-default btn-lg" id="deleteArtist" data-id="{{ venue.id }}"&gt;Delete this Artist&lt;/button&gt;
      &lt;/div&gt;
  &lt;/section&gt;
  
  &lt;script&gt;
      const btn = document.getElementById('deleteArtist');
      btn.onclick = function(e) {
          venue_id = e.target.dataset['id'];
          console.log(venue_id)
          let r = confirm("Are you sure you want to delete this venue?");
          if (r == true) {
              fetch('/deletevenue/' + venue_id, {
                  method: 'DELETE'
              })
          }
      }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>How can I get this button working?</p>