Skip to content Skip to sidebar Skip to footer

Flask And Javascript Confirm Before Deleting

I have a problem with flask app published pythonanywhere. This is a dashboard and if I click the title of the posting, it is supposed to show details of the posting. I want to add

Solution 1:

An alternative approach for a similar task:

I implemented a confirmation step before deleting post through modal by using only HTML and jinja.

{% block body %}
  <h1>Dashboard <small> Welcome {{session.username}} </small></h1><aclass="btn btn-success"href="/add_article">Add Article</a><hr><tableclass="table table-striped"><tr><th>ID</th><th>Title</th><th>Author</th><th>Date</th><th></th><th></th></tr>
    {% for article in articles %}
      <tr><td>{{article.id}}</td><td>{{article.title}}</td><td>{{article.author}}</td><td>{{article.create_date}}</td><td><ahref="edit_article/{{article.id}}"class="btn btn-default pull-right"> Edit </a></td><td><!-- Button trigger modal --><buttontype="button"class="btn btn-danger"data-toggle="modal"data-target="#exampleModalCenter{{article.id}}">
            Delete
          </button><!-- Modal --><divclass="modal fade"id="exampleModalCenter{{article.id}}"><divclass="modal-dialog modal-dialog-centered"role="document"><divclass="modal-content"><divclass="modal-header"><h5class="modal-title"id="exampleModalLongTitle{{article.id}}">Deleting Post Permanently</h5><buttontype="button"class="close"data-dismiss="modal"aria-label="Close"><spanaria-hidden="true">&times;</span></button></div><divclass="modal-body"><h3>{{article.title}}??</h3><p>Are you sure?</p></div><divclass="modal-footer"><buttontype="button"class="btn btn-secondary"data-dismiss="modal">Cancel</button><formaction="{{url_for('delete_article', id=article.id)}}"method="post"><inputtype="submit"value="Delete"class="btn btn-danger"></form></div></div></div></div></td></tr>
    {% endfor %}
  </table>
{% endblock %}

Solution 2:

Including a js file in Flask works differently:

`<scripttype="text/javascript"src="{{ url_for('static', filename='js/confirm.js') }}"></script>`

With this you should be able to load the JS

Post a Comment for "Flask And Javascript Confirm Before Deleting"