Delete Press:

URL:

from django.conf.urls import url
from django.contrib import admin
from app01 import views

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^publisher/', views.publisher),
url(r'^add_publisher/', views.add_publisher),
url(r'^del_publisher/', views.del_publisher),
]

views:
# Define the delete function: 
DEF del_publisher (Request):
# Gets you want to delete the above mentioned id:
PK = request.GET.get ( "the above mentioned id")
# in the database you want to delete the corresponding data:
models.Publisher.objects.filter (PK = PK) .Delete ()
# jump to the page you want to show:
return redirect ( "/ Publisher /")

HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

<a href="/add_publisher/">添加</a>

<table border="1">
<thead>
<tr>
<th>序号</th>
<th>id</th>
<th>出版社名称</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{% for publisher in all_publishers %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ publisher.pk }}</td>
<td>{{ publisher.name }}</td>
<td><a href="/del_publisher/?id={{ publisher.pk }}">删除</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>

Guess you like

Origin www.cnblogs.com/zhang-da/p/12037236.html