Django—View+分页

  • View


    class ArticlePulishView(View):
        def get(self,request):
            return HttpResponse("文章展示")
    
        @method_decorator(check_login)
        def post(self,request):
            return HttpResponse("发表文章")
    
    
    class DemoView(View):
        def get(self,request):
            object_list = User.objects.all()
            pagitor = Paginator(object_list,10)
            pager = pagitor.page(1)
            object_list = pager.object_list
            return render(request,'userlist.html',locals())

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <table border="1" cellspacing="0" width="80%">
        {% for user in object_list %}
        <tr>
        <td>{{ user.uid }}</td>
            <td>{{ user.username }}</td>
            <td>{{ user.password }}</td>
        </tr>
        {% endfor %}
    </table>
    <div>
        {% for current in paginator.page_range %}
            <a href="">{{ current }}</a>
        {% endfor %}
    </div>
    </body>
    </html>
发布了199 篇原创文章 · 获赞 6 · 访问量 2418

猜你喜欢

转载自blog.csdn.net/piduocheng0577/article/details/105036908
今日推荐