django高级应用(分页功能)

1、原生分页应用

前端html代码

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6 </head>
 7 <body>
 8     <ul>
 9         {% for item in posts.object_list %}
10             <li>{{ item.name }}- {{ item.age }}</li>
11         {% endfor %}
12     </ul>
13     {% include 'include/pages.html' %}
14 </body>
15 </html>
16 
17 
18 #include/pages.html
19 
20 {% if posts.has_previous %}
21     <a href="/index1.html?p={{ posts.previous_page_number }}">上一页</a>
22 {% else %}
23     <a href="#">上一页</a>
24 {% endif %}
25 
26 {% if posts.has_next %}
27     <a href="/index1.html?p={{ posts.next_page_number }}">下一页</a>
28 {% endif %}
29 <span>
30     {{ posts.number }}/{{ posts.paginator.num_pages }}
31 </span>

前端html代码