Django 2的Django分页 [英] Django paginate for django 2

查看:62
本文介绍了Django 2的Django分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对Django列表使用分页,但是我无法在线找到任何帮助,只有Django版本1.3中的旧文档

I need to use pagination to a Django list but I couldn't find any help online,, only old docs from Django version 1.3

这是我的文件:

views.py

def home(request):
    all_dress = Item.objects.all().filter(dress_active=True)
    all_good_dress = Item.objects.all().filter(dress_special=True)
    current_user = request.user
    context = {
        'all_dress': all_dress,
        'current_user': current_user,
        'all_good_dress':all_good_dress,
    }
    return render(request, 'fostania/home.html', context)

模板(html)

 {% for item in all_dress %}

        <div class="card border-info" style="width: 18rem;">
  <a href="{% url 'dress_details' item.pk%}"><img class="card-img-top" src="{{ item.dress_image1.url }}" alt="Card image cap"></a>
  <div class="card-body" align="right">
      <h5 class="card-title"><a href="{% url 'dress_details' item.pk%}">{{ item.dress_name }}</a>
          <br>{{ item.dress_action }}<br>{{ item.dress_price }} جنيه </h5>
    <p class="card-text">المقاس : {{ item.dress_size }}
    <br>{{ item.dress_city }}<br> {{ item.created_at|date:"SHORT_DATE_FORMAT" }}
    </p>
  </div>
</div>
        <br>
        <br>
                              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

      {% endfor %}

推荐答案

在此链接上找到了完整的文档和明确的方法 https://docs.djangoproject.com/en/2.0/topics/pagination/

Found the full doc and clear way to do it on this link https://docs.djangoproject.com/en/2.0/topics/pagination/

这篇关于Django 2的Django分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆