我的烧瓶博客应用需要我的帮助。 我做了一个简单的仪表板,列出了所有帖子,管理员可以编辑或删除其中的任何帖子。编辑选项很好。但是,对于删除选项,我正在尝试使用模式执行确认步骤。我的代码在下面。
{% block body %}
<h1>Dashboard <small> Welcome {{session.username}} </small></h1>
<a class="btn btn-success" href="/add_article">Add Article</a>
<hr>
<table class="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> <a href="edit_article/{{article.id}}" class="btn btn-default pull-right"> Edit </a></td>
<td>
<!-- Button trigger modal -->
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#exampleModalCenter">
Delete
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Deleting Post </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Are you sure you want to delete this post?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<form action="{{url_for('delete_article', id=article.id)}}" method="post">
<input type="submit" value="Delete" class="btn btn-danger">
</form>
</div>
</div>
</div>
</div>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}
问题:表单操作正在为所有帖子生成相同的URL(/ delete_article / 1)。 请帮忙。 关于侯赛因
答案 0 :(得分:0)
问题在于模式ID的重用。作为循环中的模式代码,所有帖子的模式都具有相同的ID。这就是为什么视图函数获得相同的URL。
解决方案(以上代码中的三个更改):
data-target =“#exampleModalCenter”-> data-target =“#exampleModalCenter {{article.id}}”
id =“ exampleModalCenter”-> id =“ exampleModalCenter {{article.id}}”
和
id =“ exampleModalLongTitle”-> id =“ exampleModalLongTitle {{article.id}}”