码迷,mamicode.com
首页 > 其他好文 > 详细

django 分页

时间:2014-10-15 19:45:51      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:style   io   for   文件   sp   div   on   cti   代码   

 

HTML代码

<div id="upload_div3">
<div style="height: 350px;width: 100%;">
<table id="tab" class="table table-bordered ">
<thead>
<tr>
<th><input id="inputname" class="inputname" type="checkbox"/></th>
<th>文件名</th>
<th>文件路径</th>
<th>文件类型</th>
<th>缩略图</th>
</tr>
</thead>
<tbody>
{% for evobj in contact.object_list %}
<tr>
<td><input name="evobjname" type="checkbox" value="{{ evobj.id }}"/></td>
<td>{{ evobj.SName }}</td>
<td>{{ evobj.SUrl }}</td>
<td>{{ evobj.SType }}</td>
<td><img src="\{{ evobj.SUrl }}" onerror="this.src=‘../../static/images/timo.jpg‘" style="width: 30px;height: 30px"></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div id="b">
<ul class="pagination">
{% if contact.has_previous %}
<li><a href="?page={{ contact.previous_page_number }}">&laquo;</a></li>
{% else %}
<li class="active"><a>&laquo;</a></li>
{% endif %}
{% for p in page_range %}
{% ifequal p contact.number %}
<li class="active"><a>{{p}}</a></li>
{% else %}
<li><a href="?page={{p}}" title="第{{p}}页">{{p}}</a><li>
{% endifequal %}
{% endfor %}
{% if contact.has_next %}
<li><a href="?page={{ contact.next_page_number }}">&raquo;</a></li>
{% else %}
<li class="active"> <a>&raquo;</a></li>
{% endif %}
</ul>
</div>
</div>

后台view代码

def seesource(request):
  sourcetype= request.GET[‘source‘]
  typelist = Smaterial.objects.filter(SType=sourcetype)
  page_range,contact = pages(request, typelist)
  return render_to_response(‘File.html‘,{‘page_range‘:page_range,‘contact‘:contact,‘sourcetype‘:sourcetype})

def pages(request,listss):
  paginator = Paginator(listss, 6) # 显示6行
  try:
    page = int(request.GET.get(‘page‘))
  except:
    page = 1
  try:
    contact = paginator.page(page)
  except(EmptyPage, InvalidPage):
    contact = paginator.page(paginator.num_pages) #页面总页数
  if page >= 5:
    page_range = paginator.page_range[page-5:page+4]
  else:
    page_range = paginator.page_range[0:page+4]
  return page_range,contact

django 分页

标签:style   io   for   文件   sp   div   on   cti   代码   

原文地址:http://www.cnblogs.com/Mohf/p/4026975.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!