Display Publisher: write the URL address corresponding to the function, the function of which check out all the publishers, objects to the template, a circular object out of each piece of data to show

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),
]

views:
Import the render django.shortcuts from 
app01 Import Models from

# the Create your views here Wallpaper.

DEF Publisher (Request):
# check out information about all publishers:
all_publishers = models.Publisher.objects.all ()
first: # returns a page parameter request, HTML pages, a dictionary: the first key is a string dictionary, the second is from the database name
return the render (Request, "publisher.html", { "all_publishers": all_publishers})

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

<table border="1">
<thead>
<tr>
<th>序号</th>
<th>id</th>
<th>出版社名称</th>
</tr>
</thead>
<tbody>
{% for publisher in all_publishers %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ publisher.pk }}</td>
<td>{{ publisher.name }}</td>
</ TR> page showing the effect of:</ HTML></ body></ Table> </ tbody>
{%} endfor%






 

 

 

Guess you like

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