gpt4 book ai didi

python - 模板中的删除按钮处于非事件状态

转载 作者:行者123 更新时间:2023-12-01 07:44:05 24 4
gpt4 key购买 nike

在此处输入代码我有一个 group_edit.html,它允许更新群组信息并将其删除。

Upade(保存)效果很好,但删除按钮不起作用。感谢帮助:我的group_edit.html:

{% block page %}
<form method="POST">
{% csrf_token %}
<div class="col-lg-4 col-md-4 col-sm-4 content">
{% bootstrap_form form %}
<button type="submit" class="btn btn-pink pull-right">Save</button>
<button type="reset" class="btn btn-warning pull-left"><a href="{% url 'confirm-delete' group_id %}"></a>Delete</button>
</div>
<a href="{% url 'group-list' %}">Back to list</a>
</form>
{% endblock %}

我的confirm_delete.html模板:

{%  block title %}Delete{%  endblock %}
{% block heading %}<h3 class="page-header-center">Object Delete</h3> {% endblock %}

{% block page %}

<form method="post">{% csrf_token %}
<p>Are you sure you want to delete "{{ obj }}"?</p>
<input type="submit" value="Confirm" class="btn btn-warning">
<a href="group_list.html" class="btn btn-default">Cancel</a>
</form>

{% endblock %}

我的观点.py:

def group_edit(request, group_id):
form = GroupForm(instance=Group.objects.get(group_id=group_id))

if request.method == "POST":
form = GroupForm(request.POST, instance=Group.objects.get(group_id=group_id))

if form.is_valid():
form.save()
messages.success(request, 'Group saved') # message for inform user of success - See messages in html file
return redirect(group_list)

return render(request, 'imports/group_edit.html', {
"group_id": group_id,
"form": form,
})


def confirm_delete(request, group_id):
obj = GroupForm(instance=Group.objects.get(group_id=group_id))
if request.method == "POST":
obj.delete()
messages.success(request, 'Deleted') # message for inform user of success - See messages in html file
return render(request, 'imports/group_list.html')

context = {
"obj": obj
}
return render(request, "imports/confirm_delete.html", context)

和我的 urls.py:

path('group_edit/<int:group_id>/', views.group_edit, name='group-edit'),
path('confirm_delete/<int:group_id>/', views.confirm_delete, name='confirm-delete'),

最佳答案

在您的链接中,跨度为 <a>是空的。所以而不是

<a href="{%  url 'confirm-delete' group_id %}"><s></a></s>Delete

应该是:

<a href="{%  url 'confirm-delete' group_id %}">Delete<b></a></b>

也许最好指定 {% url ... %}带有命名参数的参数:

<a href="{%  url 'confirm-delete' <b>group_id=</b>group_id %}">Delete</a>

关于python - 模板中的删除按钮处于非事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56551818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com